Пример #1
0
        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;

                }
            }
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
        /// <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;
        }
Пример #4
0
        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;
        }
		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;
			}
		}
        protected int removeSchedulingInfo(int clientId, int serverId, int ussId, int lssId, ref StringBuilder message)
        {
            int status = 1;
            int result = 1;
            DateTime start = DateTime.UtcNow;
            DateTime end = DateTime.MaxValue;
            ProcessAgent ls = ticketing.GetProcessAgent(serverId);
            ProcessAgentInfo lss = ticketing.GetProcessAgentInfo(lssId);
            ProcessAgentInfo uss = ticketing.GetProcessAgentInfo(ussId);
            if (ls == null)
            {
                message.AppendLine("LabServer is not specified!<br/>");
                status = 0;
            }
            if (lss == null)
            {
                message.AppendLine("LSS is not specified!<br/>");
                status = 0;
            }
            if (uss == null)
            {
                message.AppendLine("USS is not specified!<br/>");
                status = 0;
            }
            if (status < 1)
            {
                return status;
            }
            TicketLoadFactory tlf = TicketLoadFactory.Instance();
            string payload = tlf.createRevokeReservationPayload("ISB");
            Coupon coupon = ticketing.CreateTicket(TicketTypes.REVOKE_RESERVATION, lss.agentGuid, ProcessAgentDB.ServiceGuid, 300L, payload);
            ticketing.AddTicket(coupon, TicketTypes.REVOKE_RESERVATION, uss.agentGuid, ProcessAgentDB.ServiceGuid, 300L, payload);

            LabSchedulingProxy lssProxy = new LabSchedulingProxy();
            AgentAuthHeader agentHeader = new AgentAuthHeader();
            agentHeader.agentGuid = ProcessAgentDB.ServiceGuid;
            agentHeader.coupon = lss.identOut;
            lssProxy.AgentAuthHeaderValue = agentHeader;
            OperationAuthHeader opHeader = new OperationAuthHeader();
            opHeader.coupon = coupon;
            lssProxy.OperationAuthHeaderValue = opHeader;
            lssProxy.Url = lss.webServiceUrl;
            int count = lssProxy.RemoveReservation(ProcessAgentDB.ServiceGuid, "", uss.agentGuid, ls.agentGuid, labClient.clientGuid, start, end);
            result = lssProxy.RemoveExperimentInfo(ls.agentGuid, labClient.clientGuid);
            if (result > 0)
            {
                status = Math.Min(status, result);
            }

            UserSchedulingProxy ussProxy = new UserSchedulingProxy();
            AgentAuthHeader header = new AgentAuthHeader();
            header.agentGuid = ProcessAgentDB.ServiceGuid;
            header.coupon = uss.identOut;
            ussProxy.AgentAuthHeaderValue = header;
            OperationAuthHeader op2Header = new OperationAuthHeader();
            op2Header.coupon = coupon;
            ussProxy.OperationAuthHeaderValue = op2Header;
            ussProxy.Url = uss.webServiceUrl;
            int num = ussProxy.RevokeReservation(ProcessAgentDB.ServiceGuid, "", ls.agentGuid, labClient.clientGuid, start, end,
                "The USS is being removed from this lab client!");
            result = ussProxy.RemoveExperimentInfo(ls.agentGuid, labClient.clientGuid, lss.agentGuid);
            if (result > 0)
            {
                status = Math.Min(status, result);
            }
            return status;
        }
        void JunkCode()
        {
            string revoked = "revoke";
            int count = 0;
            DateTime startDate = DateTime.MinValue;
            int startHours = -1;
            int startMinutes = -1;
            DateTime endDate = DateTime.MinValue;
            int endHours = -1;
            int endMinutes = -1;

            // input error check
            try
            {
                if (txtStartMin.Text.Length > 0)
                    startMinutes = int.Parse(txtStartMin.Text);
                if (startMinutes >= 60 || startMinutes < 0)
                {
                    string msg = "Please input right form of minute in the start time ";
                    lblErrorMessage.Text = Utilities.FormatWarningMessage(msg);
                    lblErrorMessage.Visible = true;
                }
                if (txtEndMin.Text.Length > 0)
                    endMinutes = int.Parse(txtEndMin.Text);
                if (endMinutes > 60 || endMinutes < 0)
                {
                    string msg = "Please input right form of minute in the end time ";
                    lblErrorMessage.Text = Utilities.FormatWarningMessage(msg);
                    lblErrorMessage.Visible = true;
                }

                if (txtEndDate.Text.Length == 0 || txtEndDate.Text.CompareTo(culture.DateTimeFormat.ShortDatePattern) == 0)
                {
                    lblErrorMessage.Text = Utilities.FormatWarningMessage("You must enter the end date of the time block.");
                    lblErrorMessage.Visible = true;
                    return;
                }
                endDate = DateTime.Parse(txtEndDate.Text, culture);
                if (txtStartDate.Text.Length == 0 || txtStartDate.Text.CompareTo(culture.DateTimeFormat.ShortDatePattern) == 0)
                {
                    lblErrorMessage.Text = Utilities.FormatWarningMessage("You must enter the end date of the time block.");
                    lblErrorMessage.Visible = true;
                    return;
                }
                startDate = DateTime.Parse(txtStartDate.Text, culture);
                if (endDate < startDate)
                {
                    lblErrorMessage.Text = Utilities.FormatWarningMessage("The end date must be greater than or equal to the start date.");
                    lblErrorMessage.Visible = true;
                    return;
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                lblErrorMessage.Text = Utilities.FormatErrorMessage(msg);
                lblErrorMessage.Visible = true;
            }

            startHours = int.Parse(ddlStartHour.SelectedItem.Text);

            endHours = int.Parse(ddlEndHour.SelectedItem.Text);

            DateTime startTime = new DateTime(startDate.Year, startDate.Month, startDate.Day,
                startHours, startMinutes, 0, DateTimeKind.Utc);
            startTime.AddMinutes(userTZ);
            DateTime endTime = new DateTime(endDate.Year, endDate.Month, endDate.Day,
                endHours, endMinutes, 0, DateTimeKind.Utc);
            endTime.AddMinutes(userTZ);

            //Ticket ticketforRevo = ticketRetrieval.RetrieveAndVerify(coupon, TicketTypes.REVOKE_RESERVATION);

            // the removed reservations on LSS
            ArrayList removedRes = new ArrayList();
            ArrayList ussGuids = new ArrayList();

            if (startTime > endTime)
            {
                string msg = "the start time should be earlier than the end time";
                lblErrorMessage.Text = Utilities.FormatWarningMessage(msg);
                lblErrorMessage.Visible = true;
                return;
            }
            try
            {
                //the reservations going to be removed
                int[] resIDs = dbManager.ListReservationInfoIDsByLabServer(Session["lsGuid"].ToString(), startTime, endTime);
                if (resIDs != null && resIDs.Length > 0)
                {
                    count = dbManager.RevokeReservations(resIDs, txtMessage.Text);
                    lblErrorMessage.Text = Utilities.FormatConfirmationMessage("For the time period "
                        + DateUtil.ToUserTime(startTime, culture, userTZ) + " to "
                    + DateUtil.ToUserTime(endTime, culture, userTZ) + ", " + count + " out of " + resIDs.Length + " reservations have been revoked successfully.");
                    lblErrorMessage.Visible = true;
                }

            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = Utilities.FormatErrorMessage("The related reservations have not been revoked successfully." + ex.Message);
                lblErrorMessage.Visible = true;
                // rollback
                foreach (ReservationInfo resInfo in removedRes)
                {
                    dbManager.AddReservationInfo(resInfo.startTime, resInfo.endTime,
                        resInfo.credentialSetId, resInfo.experimentInfoId, resInfo.resourceId, resInfo.ussId, resInfo.statusCode);

                }
                return;
            }

            try
            {

                foreach (string uGuid in ussGuids)
                {
                    int uInfoID = dbManager.ListUSSInfoID(uGuid);
                    USSInfo[] ussArray = dbManager.GetUSSInfos(new int[] { uInfoID });
                    if (ussArray.Length > 0)
                    {
                        Coupon revokeCoupon = dbManager.GetCoupon(ussArray[0].revokeCouponId, ussArray[0].domainGuid);

                        UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                        ussProxy.Url = ussArray[0].ussUrl;

                        //assign the coupon from ticket to the soap header;
                        OperationAuthHeader opHeader = new OperationAuthHeader();
                        opHeader.coupon = revokeCoupon;
                        ussProxy.OperationAuthHeaderValue = opHeader;

                        //if (ussProxy.RevokeReservation(Session["lsGuid"].ToString(), startTime, endTime))
                        //{
                        //    lblErrorMessage.Text = Utilities.FormatConfirmationMessage(" The related reservations have been revoked successfully !");
                        //    lblErrorMessage.Visible = true;
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = Utilities.FormatErrorMessage("The related reservation have not been revoked successfully." + ex.Message);
                lblErrorMessage.Visible = true;
                // rollback
                foreach (ReservationInfo resInfo in removedRes)
                {
                    dbManager.AddReservationInfo(resInfo.startTime, resInfo.endTime, resInfo.credentialSetId, resInfo.experimentInfoId, resInfo.resourceId, resInfo.ussId, resInfo.statusCode);

                }
            }
        }
Пример #8
0
        void getTimePeriods()
        {
            OperationAuthHeader opHeader = new OperationAuthHeader();
            opHeader.coupon = coupon;
            LabSchedulingProxy lssProxy = new LabSchedulingProxy();
            lssProxy.Url = lssURL;
            lssProxy.OperationAuthHeaderValue = opHeader;

            TimePeriod[] availablePeriods = lssProxy.RetrieveAvailableTimePeriods(serviceBrokerGuid, groupName,
                "", labServerGuid, clientGuid, startTime, endTime);
            if (availablePeriods == null)
            {
                string msg = "There are no available time slots for this experiment.";
                lblErrorMessage.Text = Utilities.FormatWarningMessage(msg);
                lblErrorMessage.Visible = true;
                btnMakeReservation.Visible = false;
               // btnMakeReservation1.Visible = false;
                cntrScheduling.Visible=false;
            }
            else{
                if (availablePeriods.Length > 0)
                {
                    minTime = availablePeriods[0].quantum > minRequiredTime.TotalMinutes
                        ? TimeSpan.FromMinutes(availablePeriods[0].quantum) : minRequiredTime;
                }
                cntrScheduling.Visible = true;
                cntrScheduling.StartTime = startTime;
                cntrScheduling.EndTime = endTime;
                cntrScheduling.UserTZ = userTZ;
                cntrScheduling.Culture = culture;

                cntrScheduling.DataSource = availablePeriods;
                cntrScheduling.DataBind();
            }
        }
Пример #9
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            int groupID = 0;
            string groupName = null;
            lc = wrapper.GetLabClientsWrapper(new int[] { Convert.ToInt32(Session["ClientID"]) })[0];

            if (Session["GroupID"] != null && Session["GroupID"].ToString().Length > 0)
            {
                groupID = Convert.ToInt32(Session["GroupID"]);
            }
            if (Session["GroupName"] != null && Session["GroupName"].ToString().Length > 0)
            {
                groupName = Session["GroupName"].ToString();

                lblGroupNameTitle.Text = groupName;
                lblBackToLabs.Text = groupName;

                if (Convert.ToInt32(Session["ClientCount"]) == 1)
                    lblGroupNameSystemMessage.Text = "Messages for " + groupName;
                else
                    lblGroupNameSystemMessage.Text = "Messages for " + lc.clientName;
            }

            if (!IsPostBack)
            {
                auto = Request.QueryString["auto"];
                if (auto!= null && auto.Length > 0)
                {
                    if (auto.ToLower().Contains("t"))
                    {
                        autoLaunch = true;
                    }
                }
                if (lc.clientType == LabClient.INTERACTIVE_APPLET || lc.clientType == LabClient.INTERACTIVE_HTML_REDIRECT)
                {
                    // retrieve parameters from URL
                    couponId = Request.QueryString["coupon_id"];
                    passkey = Request.QueryString["passkey"];
                    issuerGuid = Request.QueryString["issuer_guid"];

                    if (lc.needsScheduling)
                    {
                        Coupon opCoupon = null;
                        if (couponId != null && passkey != null && issuerGuid != null)
                        {
                            opCoupon = new Coupon(issuerGuid, Int64.Parse(couponId), passkey);

                            // First check for an Allow Execution Ticket
                            Ticket allowExperimentExecutionTicket = issuer.RetrieveTicket(
                                opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION);
                            if (allowExperimentExecutionTicket == null)
                            {
                                // Try for a reservation

                                int ussId = issuer.FindProcessAgentIdForClient(lc.clientID, ProcessAgentType.SCHEDULING_SERVER);
                                if (ussId > 0)
                                {
                                    ProcessAgent uss = issuer.GetProcessAgent(ussId);
                                    ProcessAgent ls = issuer.GetProcessAgent(lc.labServerIDs[0]);

                                    UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                                    OperationAuthHeader op = new OperationAuthHeader();
                                    op.coupon = opCoupon;
                                    ussProxy.Url = uss.webServiceUrl;
                                    ussProxy.OperationAuthHeaderValue = op;
                                    Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid, Session["UserName"].ToString(), ls.agentGuid, lc.clientGuid);

                                    if (reservation != null)
                                    {
                                        // Find efective group
                                        string effectiveGroupName = null;
                                        int effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(groupID, lc.clientID,
                                            Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType);
                                        if (effectiveGroupID == groupID)
                                        {
                                            if (Session["groupName"] != null)
                                            {
                                                effectiveGroupName = Session["groupName"].ToString();
                                            }
                                            else
                                            {
                                                effectiveGroupName = AdministrativeAPI.GetGroupName(groupID);
                                                Session["groupName"] = effectiveGroupName;
                                            }
                                        }
                                        else if (effectiveGroupID > 0)
                                        {
                                            effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID);
                                        }
                                        // create the allowExecution Ticket
                                        DateTime start = reservation.Start;
                                        long duration = reservation.Duration;
                                        string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload(
                                            start, duration, effectiveGroupName);
                                        DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond);
                                        DateTime utcNow = DateTime.UtcNow;
                                        long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond;
                                        allowExperimentExecutionTicket = issuer.AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION,
                                                ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload);
                                    }
                                }
                            }
                            if (allowExperimentExecutionTicket != null)
                            {
                                XmlDocument payload = new XmlDocument();
                                payload.LoadXml(allowExperimentExecutionTicket.payload);
                                startExecution = DateUtil.ParseUtc(payload.GetElementsByTagName("startExecution")[0].InnerText);
                                duration = Int64.Parse(payload.GetElementsByTagName("duration")[0].InnerText);

                                Session["StartExecution"] = DateUtil.ToUtcString(startExecution);
                                Session["Duration"] = duration;

                                //groupId = payload.GetElementsByTagName("groupID")[0].InnerText;

                                // Display reenter button if experiment is reentrant & a current experiment exists
                                if (lc.IsReentrant)
                                {

                                    long[] ids = InternalDataDB.RetrieveActiveExperimentIDs(Convert.ToInt32(Session["UserID"]),
                                        Convert.ToInt32(Session["GroupID"]), lc.labServerIDs[0], lc.clientID);
                                    if (ids.Length > 0)
                                    {
                                        btnLaunchLab.Text = "Launch New Experiment";
                                        btnLaunchLab.Visible = true;
                                        pReenter.Visible = true;
                                        btnReenter.Visible = true;
                                        btnReenter.CommandArgument = ids[0].ToString();
                                    }
                                    else
                                    {

                                        pReenter.Visible = false;
                                        btnReenter.Visible = false;
                                        btnLaunchLab.Text = "Launch Lab";
                                        if (autoLaunch)
                                        {
                                            launchLabClient(lc.clientID);
                                        }
                                        else
                                        {
                                            btnLaunchLab.Visible = true;
                                        }
                                    }
                                }
                                else
                                {
                                    if (autoLaunch)
                                    {
                                        launchLabClient(lc.clientID);
                                    }
                                    else
                                    {
                                        btnLaunchLab.Visible = true;
                                    }
                                }
                            }
                            else
                            {
                                btnLaunchLab.Visible = false;
                            }
                        }
                    }
                    else
                    {
                        if (autoLaunch)
                        {
                            launchLabClient(lc.clientID);
                        }
                        else
                        {
                            btnLaunchLab.Visible = true;
                        }
                    }
                }
                else if (lc.clientType == LabClient.BATCH_APPLET || lc.clientType == LabClient.BATCH_HTML_REDIRECT)
                {
                    if (autoLaunch)
                    {
                        launchLabClient(lc.clientID);
                    }
                    else
                    {
                        btnLaunchLab.Visible = true;
                    }
                }
            }

            btnSchedule.Visible = lc.needsScheduling;
            //Session["LoaderScript"] = lc.loaderScript;
            lblClientName.Text = lc.clientName;
            lblVersion.Text = lc.version;
            lblLongDescription.Text = lc.clientLongDescription;
            lblNotes.Text = lc.notes;
            string emailCmd = "mailto:" + lc.contactEmail;
            lblEmail.Text = "<a href=" + emailCmd + ">" + lc.contactEmail + "</a>";

            btnLaunchLab.Command += new CommandEventHandler(this.btnLaunchLab_Click);
            btnLaunchLab.CommandArgument = lc.clientID.ToString();

            int count = 0;

            if (lc.clientInfos != null)
            {
                foreach (ClientInfo ci in lc.clientInfos)
                {
                    if (ci.infoURLName.CompareTo("Documentation") != 0)
                    {
                        System.Web.UI.WebControls.Button b = new System.Web.UI.WebControls.Button();
                        b.Visible = true;
                        b.CssClass = "button";
                        b.Text = ci.infoURLName;
                        b.CommandArgument = ci.infoURL;
                        b.CommandName = ci.infoURLName;
                        b.ToolTip = ci.description;
                        b.Command += new CommandEventHandler(this.HelpButton_Click);
                        repClientInfos.Controls.AddAt(count, b);
                        repClientInfos.Controls.AddAt(count + 1, new LiteralControl("&nbsp;&nbsp;"));
                        count += 2;
                    }
                }
            }

            List<SystemMessage> messagesList = new List<SystemMessage>();
            SystemMessage[] groupMessages = null;
            if (Session["ClientCount"] != null && Convert.ToInt32(Session["ClientCount"]) == 1)
            {
                groupMessages = wrapper.GetSystemMessagesWrapper(SystemMessage.GROUP, Convert.ToInt32(Session["GroupID"]), 0, 0);
                if (groupMessages != null)
                    messagesList.AddRange(groupMessages);
            }

            foreach (int labServerID in lc.labServerIDs)
            {
                SystemMessage[] labMessages = wrapper.GetSystemMessagesWrapper(SystemMessage.LAB, 0, 0, labServerID);
                if (labMessages != null)
                    messagesList.AddRange(labMessages);
            }

            if (messagesList != null && messagesList.Count > 0)
            {
                messagesList.Sort(SystemMessage.CompareDateDesc);
                //messagesList.Reverse();
                repSystemMessage.DataSource = messagesList;
                repSystemMessage.DataBind();
            }

            else
            {

                lblGroupNameSystemMessage.Text += "</h3><p>No Messages at this time</p><h3>";

            }
        }
        protected int revokeReservations(int resourceId, int expId, int credId, DateTime start, DateTime end, ref StringBuilder message)
        {
            int status = 0;
            int count = 0;
            Dictionary<int, List<ReservationData>> reservations = new Dictionary<int, List<ReservationData>>();
            try{
            ReservationData[] data = dbManager.RetrieveReservationData(resourceId, expId, credId, start, end);
            if (data != null && data.Length > 0)
            {

                // get  list for each USS
                foreach (ReservationData rd in data)
                {
                    if (!reservations.ContainsKey(rd.ussId))
                    {
                        List<ReservationData> lst = new List<ReservationData>();
                        reservations.Add(rd.ussId, lst);
                    }
                    reservations[rd.ussId].Add(rd);
                }
                foreach (int uid in reservations.Keys)
                {
                    if (uid > 0)
                    {
                        USSInfo uss = dbManager.GetUSSInfo(uid);
                        if (uss != null)
                        {
                            UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                            OperationAuthHeader header = new OperationAuthHeader();
                            header.coupon = dbManager.GetCoupon(uss.revokeCouponId, uss.domainGuid);
                            ussProxy.OperationAuthHeaderValue = header;
                            ussProxy.Url = uss.ussUrl;
                            foreach (ReservationData res in reservations[uid])
                            {

                                int num = ussProxy.RevokeReservation(res.sbGuid, res.groupName,
                                    res.labServerGuid, res.clientGuid, res.Start, res.End, txtMessage.Text);
                                //if (num > 0)
                                //{
                                    dbManager.RemoveReservationInfoByIDs(new int[] { res.reservationID });
                                    count += 1;
                                //}
                                status = 1;
                            }
                        }
                    }
                    else
                    {
                        foreach (ReservationData res in reservations[uid])
                        {
                            dbManager.RemoveReservationInfoByIDs(new int[] { res.reservationID });
                            status = 1;
                            count += 1;
                        }
                    }
                }
                message.AppendLine( count.ToString() + " reservations were revoked!");
            }
            }
            catch(Exception e){
                status = -1;
                message.AppendLine(e.Message);
                return status;
            }
            return count;
        }
Пример #11
0
        protected void launchLabXX(int userID, int groupID, int clientID)
        {
            // Currently there is not a good solution for checking for an AllowExperiment ticket, will check the USS for reservation
            Coupon allowExecutionCoupon = null;
            StringBuilder message = new StringBuilder("Message: clientID = " + clientID);
            LabClient client = AdministrativeAPI.GetLabClient(clientID);
            string userName = null;
            Coupon opCoupon = null;
            Ticket allowTicket = null;

            if (Session["UserID"] != null)
            {
                if (userID == Convert.ToInt32(Session["UserID"]))
                {
                    userName = Session["UserName"].ToString();
                }
                else
                {
                    userName = AdministrativeAPI.GetUserName(userID);
                    Session["UserID"] = userID;
                    Session["UserName"] = userName;
                }
                string groupName = AdministrativeAPI.GetGroupName(groupID);
                if (client.clientID > 0) // It's a structure need to test for valid value
                {
                    // create the RecipeExecutor

                    string redirectURL = null;
                    DateTime start = DateTime.UtcNow;
                    long duration = 36000L; // default is ten hours
                    ProcessAgentInfo labServer = null;

                    if (client.labServerIDs.Length > 0)
                    {
                        labServer = issuer.GetProcessAgentInfo(client.labServerIDs[0]);
                    }
                    else
                    {
                        throw new Exception("The lab server is not specified for lab client " + client.clientName + " version: " + client.version);
                    }

                    //Check for Scheduling:
                    if (client.needsScheduling)
                    {
                        int ussId = issuer.FindProcessAgentIdForClient(client.clientID, ProcessAgentType.SCHEDULING_SERVER);
                        if (ussId > 0)
                        {
                            ProcessAgent uss = issuer.GetProcessAgent(ussId);

                            //// Find efective group
                            //string effectiveGroupName = null;
                            //int effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(groupID, clientID,
                            //    Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType);
                            //if (effectiveGroupID == groupID)
                            //{
                            //    if(Session["groupName"] != null){
                            //        effectiveGroupName = Session["groupName"].ToString();
                            //    }
                            //    else{
                            //        effectiveGroupName = AdministrativeAPI.GetGroupName(groupID);
                            //        Session["groupName"] = effectiveGroupName;
                            //    }
                            //}
                            //else if (effectiveGroupID > 0)
                            //{
                            //   effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID );
                            //}

                            int lssId = issuer.FindProcessAgentIdForAgent(client.labServerIDs[0], ProcessAgentType.LAB_SCHEDULING_SERVER);
                            ProcessAgent lss = issuer.GetProcessAgent(lssId);

                            // check for current reservation
                            string redeemPayload = TicketLoadFactory.Instance().createRedeemReservationPayload(DateTime.UtcNow, DateTime.UtcNow);
                            opCoupon = issuer.CreateTicket(TicketTypes.REDEEM_RESERVATION, uss.agentGuid, ProcessAgentDB.ServiceGuid, 600, redeemPayload);
                            UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                            OperationAuthHeader op = new OperationAuthHeader();
                            op.coupon = opCoupon;
                            ussProxy.Url = uss.webServiceUrl;
                            ussProxy.OperationAuthHeaderValue = op;
                            Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid, userName, labServer.agentGuid, client.clientGuid);
                            if (reservation != null)
                            {
                                start = reservation.Start;
                                duration = reservation.Duration;
                                string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload(
                                    start, duration, groupName);
                                DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond);
                                DateTime utcNow = DateTime.UtcNow;
                                long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond;
                                allowTicket = issuer.AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION,
                                        ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload);
                            }
                            else
                            {

                                string schedulingUrl = RecipeExecutor.Instance().ExecuteExerimentSchedulingRecipe(uss.agentGuid, lss.agentGuid, userName, groupName,
                                    labServer.agentGuid, client.clientGuid, client.clientName, client.version,
                                    Convert.ToInt64(ConfigurationSettings.AppSettings["scheduleSessionTicketDuration"]), Convert.ToInt32(Session["UserTZ"]));

                                schedulingUrl += "&sb_url=" + ProcessAgentDB.ServiceAgent.codeBaseUrl + "/myClient.aspx";
                                Response.Redirect(schedulingUrl, true);
                            }
                        }
                    }

                    if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT)
                    {
                        if (client.IsReentrant) // check for an existing active experiment
                        {
                            long[] ids = InternalDataDB.RetrieveActiveExperimentIDs(userID, groupID, client.labServerIDs[0], client.clientID);
                            if (ids.Length > 0)
                            {
                                long[] coupIDs = InternalDataDB.RetrieveExperimentCouponIDs(ids[0]);
                                Coupon coupon = issuer.GetIssuedCoupon(coupIDs[0]);
                                // 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=" + issuer.GetIssuerGuid());

                                // Add the return url to the redirect
                                url.Append("&sb_url=");
                                url.Append(ProcessAgentDB.ServiceAgent.codeBaseUrl +"/myClient.aspx");

                                // Now open the lab within the current Window/frame
                                Response.Redirect(url.ToString(), true);
                            }
                        }

                        //Check for Scheduling:
                        if (client.needsScheduling)
                        {
                            //The scheduling Ticket should exist and been parsed into the session
                            if (allowTicket == null)
                            {
                                throw new Exception(" Unable to confirm a reservation for this client.");
                            }

                        }
                        // execute the "experiment execution recipe
                        redirectURL = RecipeExecutor.Instance().ExecuteExperimentExecutionRecipe(labServer, client,
                        start, duration, Convert.ToInt32(Session["UserTZ"]), userID,
                        groupID, (string)Session["GroupName"]);

                        // Add the return url to the redirect
                        redirectURL += "&sb_url=" + ProcessAgentDB.ServiceAgent.codeBaseUrl +"/myClient.aspx";

                        // Now open the lab within the current Window/frame
                        Response.Redirect(redirectURL, true);

                    }
                    else if (client.clientType == LabClient.INTERACTIVE_APPLET)
                    {
                        // Note: Currently not supporting Interactive applets
                        // use the Loader script for Batch experiments
                        // This assumes that the client will request the experiment creation

                        Session["LoaderScript"] = client.loaderScript;
                        Session.Remove("RedirectURL");

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

                    // Support for Batch 6.1 Lab Clients
                    else if (client.clientType == LabClient.BATCH_HTML_REDIRECT)
                    {
                        Session["ClientID"] = client.clientID;
                        AdministrativeAPI.SetSessionClient(Convert.ToInt64(Session["SessionID"]), client.clientID);
                        // use the Loader script for Batch experiments

                        //use ticketing & redirect to url in loader script

                        // [GeneralTicketing] retrieve static process agent corresponding to the first
                        // association lab server */

                        // New comments: The HTML Client is not a static process agent, so we don't search for that at the moment.
                        // Presumably when the interactive SB is merged with the batched, this should check for a static process agent.
                        // - CV, 7/22/05

                        Session.Remove("LoaderScript");

                        //payload includes username and effective group name & client id.
                        //ideally this should be encoded in xml  - CV, 7/27/2005
                        TicketLoadFactory factory = TicketLoadFactory.Instance();
                        string uName = (string)Session["UserName"];
                        string gName = (string)Session["GroupName"];

                        string sessionPayload = factory.createRedeemSessionPayload(userID,
                           groupID, clientID, uName, gName);
                        // SB is the redeemer, ticket type : session_identifcation, no expiration time, payload,SB as sponsor ID, redeemer(SB) coupon
                        Coupon coupon = issuer.CreateTicket(TicketTypes.REDEEM_SESSION, ProcessAgentDB.ServiceGuid,
                             ProcessAgentDB.ServiceGuid, -1, sessionPayload);

                        string jScript = @"<script language='javascript'> window.open ('" + client.loaderScript + "?couponID=" + coupon.couponId + "&passkey=" + coupon.passkey + "')</script>";
                        Page.RegisterStartupScript("HTML Client", jScript);
                    }
                }
                // use the Loader script for Batch experiments
                else if (client.clientType == LabClient.BATCH_APPLET)
                {
                    Session["ClientID"] = client.clientID;
                    AdministrativeAPI.SetSessionClient(Convert.ToInt64(Session["SessionID"]), client.clientID);
                    Session["LoaderScript"] = client.loaderScript;
                    Session.Remove("RedirectURL");

                    string jScript = @"<script language='javascript'>parent.theapplet.location.href = '"
                        + ProcessAgentDB.ServiceAgent.codeBaseUrl + @"/applet.aspx" + @"'</script>";
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "ReloadFrame", jScript);

                }
            }
            else
            {
                message.Append(" LabServer = null");
            }
            //lblDebug.Text = message.ToString();
            Utilities.WriteLog(message.ToString());
        }
Пример #12
0
        protected void launchLab(int userID, int groupID, int clientID)
        {
            // Currently there is not a good solution for checking for an AllowExperiment ticket, will check the USS for reservation
            StringBuilder buf = new StringBuilder("~/myClient.aspx?auto=t");

            string userName = null;
            Coupon opCoupon = null;
            Ticket allowTicket = null;
            int effectiveGroupID = 0;
            if (Session["UserName"] != null && Session["UserName"].ToString().Length > 0)
            {
                userName = Session["UserName"].ToString();
            }
            else
            {
                userName = AdministrativeAPI.GetUserName(userID);
            }

              LabClient client = AdministrativeAPI.GetLabClient(clientID);
              if (client.clientID > 0) // It's a structure need to test for valid value
              {
                    DateTime start = DateTime.UtcNow;
                    long duration = 36000L; // default is ten hours
                    ProcessAgentInfo labServer = null;

                    if (client.labServerIDs.Length > 0)
                    {
                        labServer = issuer.GetProcessAgentInfo(client.labServerIDs[0]);
                    }
                    else
                    {
                        throw new Exception("The lab server is not specified for lab client " + client.clientName + " version: " + client.version);
                    }
                    // Find efective group
                    string effectiveGroupName = null;
                    effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(groupID, clientID,
                        Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType);
                    if (effectiveGroupID == groupID)
                    {
                        if (Session["groupName"] != null)
                        {
                            effectiveGroupName = Session["groupName"].ToString();
                        }
                        else
                        {
                            effectiveGroupName = AdministrativeAPI.GetGroupName(groupID);
                            Session["groupName"] = effectiveGroupName;
                        }
                    }
                    else if (effectiveGroupID > 0)
                    {
                        effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID);
                    }

                    //Check for Scheduling:
                    if (client.needsScheduling)
                    {
                        int ussId = issuer.FindProcessAgentIdForClient(client.clientID, ProcessAgentType.SCHEDULING_SERVER);
                        if (ussId > 0)
                        {
                            ProcessAgent uss = issuer.GetProcessAgent(ussId);

                            int lssId = issuer.FindProcessAgentIdForAgent(client.labServerIDs[0], ProcessAgentType.LAB_SCHEDULING_SERVER);
                            ProcessAgent lss = issuer.GetProcessAgent(lssId);

                            // check for current reservation

                            //create a collection & redeemTicket
                            string redeemPayload = TicketLoadFactory.Instance().createRedeemReservationPayload(DateTime.UtcNow, DateTime.UtcNow);
                            opCoupon = issuer.CreateTicket(TicketTypes.REDEEM_RESERVATION, uss.agentGuid, ProcessAgentDB.ServiceGuid, 600, redeemPayload);

                            UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                            OperationAuthHeader op = new OperationAuthHeader();
                            op.coupon = opCoupon;
                            ussProxy.Url = uss.webServiceUrl;
                            ussProxy.OperationAuthHeaderValue = op;
                            Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid, userName, labServer.agentGuid, client.clientGuid);

                            if (reservation != null)
                            {
                                // create the allowExecution Ticket
                                start = reservation.Start;
                                duration = reservation.Duration;
                                string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload(
                                    start, duration, effectiveGroupName);
                                DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond);
                                DateTime utcNow = DateTime.UtcNow;
                                long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond;
                                allowTicket = issuer.AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION,
                                        ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload);
                                // Append op coupon to url
                                buf.Append("&coupon_id=" + opCoupon.couponId);
                                buf.Append("&passkey=" + opCoupon.passkey);
                                buf.Append("&issuer_guid=" + opCoupon.issuerGuid);
                            }
                            //else
                            //{

                            //    string schedulingUrl = RecipeExecutor.Instance().ExecuteExerimentSchedulingRecipe(uss.agentGuid, lss.agentGuid, userName, groupName,
                            //        labServer.agentGuid, client.clientGuid, client.clientName, client.version,
                            //        Convert.ToInt64(ConfigurationSettings.AppSettings["scheduleSessionTicketDuration"]), Convert.ToInt32(Session["UserTZ"]));

                            //    schedulingUrl += "&sb_url=" + ProcessAgentDB.ServiceAgent.codeBaseUrl + "/myClient.aspx";
                            //    Response.Redirect(schedulingUrl, true);
                            //}
                        }
                        else{
                            // USS Not Found
                        }
                    } // End needsScheduling
                  //Response.Redirect(Global.FormatRegularURL(Request, "myClient.aspx"), true);
                  Response.Redirect(buf.ToString(), true);
                  } // End if valid client
              else{
                throw new Exception("The specified lab client could not be found");
              }
        }
Пример #13
0
        /* TO DO */
        public int RevokeReservation(ReservationInfo ri, string message)
        {
            int count = 0;
            LssCredentialSet[] sets = GetCredentialSets(new int[] { ri.credentialSetId });
            LssExperimentInfo[] exps = GetExperimentInfos(new int[] { ri.experimentInfoId });
            if (sets != null && sets.Length > 0 && exps != null && exps.Length > 0)
            {

                USSInfo uss = GetUSSInfo(ri.ussId);
                if (uss != null)
                {

                    UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                    OperationAuthHeader header = new OperationAuthHeader();
                    header.coupon = GetCoupon(uss.revokeCouponId, uss.domainGuid);
                    ussProxy.OperationAuthHeaderValue = header;
                    ussProxy.Url = uss.ussUrl;

                    int num = ussProxy.RevokeReservation(sets[0].serviceBrokerGuid, sets[0].groupName,
                        exps[0].labServerGuid, exps[0].labClientGuid, ri.Start, ri.End, message);
                    if (num > 0)
                    {
                        RemoveReservationInfoByIDs(new int[] { ri.reservationInfoId });
                        count += num;
                    }
                }
            }

            return count;
        }
Пример #14
0
        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;
            }
        }
Пример #15
0
        public static int RevokeReservation(ReservationInfo ri)
        {
            int count = 0;
            LssCredentialSet[] sets = DBManager.GetCredentialSets(new int[] { ri.credentialSetId });
            LssExperimentInfo[] exps = DBManager.GetExperimentInfos(new int[] { ri.experimentInfoId });
            if (sets != null && sets.Length > 0 && exps != null && exps.Length > 0)
            {

                USSInfo uss = DBManager.GetUSSInfo(sets[0].ussGuid);
                if (uss != null)
                {
                    ProcessAgentDB paDB = new ProcessAgentDB();
                    UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                    OperationAuthHeader header = new OperationAuthHeader();
                    header.coupon = paDB.GetCoupon(uss.couponId, uss.domainGuid);
                    ussProxy.OperationAuthHeaderValue = header;
                    ussProxy.Url = uss.ussUrl;

                    int num = ussProxy.RevokeReservation(sets[0].serviceBrokerGuid, sets[0].groupName,
                        exps[0].labServerGuid, exps[0].labClientGuid, ri.Start, ri.End, "The reservation time assigned to this reservation is being removed");
                    if (num > 0)
                    {
                        LSSSchedulingAPI.RemoveReservationInfoByIDs(new int[] { ri.reservationInfoId });
                        count += num;
                    }
                }
             }

            return count;
        }
Пример #16
0
        /// <summary>
        /// Should handle all requests to launch a lab, produces a releative URL or error message 
        /// and a status code which are returned in the IntTag. This does not make use of the 'Context'.
        /// This should only be called after the original request has been authorized since the
        /// user is assummed to have been authenticated and authorized.
        /// </summary>
        /// <param name="opCoupon">An initial operationCoupon</param>
        /// <param name="clientID"></param>
        /// <param name="labServerID"></param>
        /// <param name="groupID">specified by SCO, may not be the users group</param>
        /// <param name="userID"></param>
        /// <returns>A negative value for errrors or a bitmapped value indicating what should be done with the result.tag</returns>
        public IntTag ProcessLaunchClientRequest(Coupon opCoupon, int clientID, int labServerID,
            int groupID, int userID, int userTZ //, string authorityUrl, long duration, int autoStart
            )
        {
            int effectiveGroupID = -1;
            int userGroupID = -1;
            string groupName = null;
            string effectiveGroupName = null;
            string userName = null;
            DateTime startExecution =DateTime.MinValue;
            long duration = -1L;

            ProcessAgentInfo labServer = null;
            StringBuilder buf = new StringBuilder();
            LabClient client = AdministrativeAPI.GetLabClient(clientID);
            iLabParser parser = new iLabParser();
            IntTag result = new IntTag(-1, "Access Denied");

            if (client == null)
            {
               result.tag = "LabClient was not found";
               return result;
            }
            userName = AdministrativeAPI.GetUserName(userID);
            if(String.IsNullOrEmpty(userName)){
                result.tag = "User was not found";
                return result;
            }
            // Check if user is a member of the specified group
            List<int> allGroups = new List<int>(AdministrativeAPI.ListGroupIDsForUserRecursively(userID));
            if(!allGroups.Contains(groupID)){
                result.tag = "User does not have access to the specified group";
                return result;
            }
            //TODO
            int qualID = AuthorizationAPI.GetQualifierID(clientID, Qualifier.labClientQualifierTypeID);
            int[] clientGroups = AuthorizationAPI.FindGrants(-1, Function.useLabClientFunctionType, qualID);
            // Find the users actual group and run as that group

            List<int> userGroups = new List<int>(AdministrativeAPI.ListGroupIDsForUser(userID));
            if (userGroups.Count == 1)
            {
                groupName = AdministrativeAPI.GetGroupName(userGroups[0]);
            }
            else if (userGroups.Count > 1)
            {

            }
            //TODO This does not seem to be working
            effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(groupID, clientID,
               Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType);
            if (effectiveGroupID == groupID)
            {
                effectiveGroupName = groupName;
            }
            else if (effectiveGroupID > 0)
            {
                effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID);
            }

            ProcessAgentInfo[] paInfos = AdministrativeAPI.GetLabServersForClient(clientID);
            if (paInfos != null && paInfos.Length > 0)
            {
                labServer = paInfos[0];
            }

            if (client.needsScheduling)
            {
                  Ticket allowExperimentExecutionTicket = null;
                        if (opCoupon != null)
                        {
                            // First check for an Allow Execution Ticket
                            allowExperimentExecutionTicket = RetrieveTicket(
                                opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION);
                        }
                        if (allowExperimentExecutionTicket == null)
                        {
                            // Try for a reservation
                            int ussId = FindProcessAgentIdForClient(client.clientID, ProcessAgentType.SCHEDULING_SERVER);
                            if (ussId > 0)
                            {
                                ProcessAgent uss = GetProcessAgent(ussId);
                                // check for current reservation

                                //create a collection & redeemTicket
                                string redeemPayload = TicketLoadFactory.Instance().createRedeemReservationPayload(DateTime.UtcNow,
                                    DateTime.UtcNow, userName, userID,
                                    groupName, client.clientGuid);

                                 Coupon redeemCoupon = CreateCoupon();

                                AddTicket(redeemCoupon, TicketTypes.REDEEM_RESERVATION, uss.agentGuid,
                                    ProcessAgentDB.ServiceGuid, 600, redeemPayload);

                                UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                                OperationAuthHeader op = new OperationAuthHeader();
                                op.coupon = redeemCoupon;
                                ussProxy.Url = uss.webServiceUrl;
                                ussProxy.OperationAuthHeaderValue = op;
                                Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid,
                                    userName, labServer.agentGuid, client.clientGuid);
                                if (reservation != null)
                                {

                                    // create the allowExecution Ticket
                                    DateTime start = reservation.Start;
                                    duration = reservation.Duration;
                                    string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload(
                                        start, duration, effectiveGroupName,client.clientGuid);
                                    DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond);
                                    DateTime utcNow = DateTime.UtcNow;
                                    long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond;
                                    allowExperimentExecutionTicket = AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION,
                                            ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload);
                                }
                            }
                        }
                        if (allowExperimentExecutionTicket != null)
                        {
                            XmlDocument payload = new XmlDocument();
                            payload.LoadXml(allowExperimentExecutionTicket.payload);
                            startExecution = DateUtil.ParseUtc(payload.GetElementsByTagName("startExecution")[0].InnerText);
                            duration = Int64.Parse(payload.GetElementsByTagName("duration")[0].InnerText);
                        }
                        else{ // No current scheduled reservations
                            result.id = -8;
                            result.tag = "Go to USS";
                            return result;
                        }

            }
            else // Not Scheduled
            {
            }
                ///////////////////////////

                if (labServer != null)
                {
                    if (client.IsReentrant)
                    {
                        long[] ids = InternalDataDB.RetrieveActiveExperimentIDs(userID,
                                       effectiveGroupID, labServer.agentId,client.clientID);
                        foreach (long id in ids)
                        {
                            InternalDataDB.CloseExperiment(id, StorageStatus.CLOSED_USER);
                        }
                    }
                    TicketLoadFactory factory = TicketLoadFactory.Instance();
                    // 1. Create Coupon for ExperimentCollection
                    Coupon expCoupon = CreateCoupon();

                    iLabProperties properties = new iLabProperties();
                    properties.Add("sb", ProcessAgentDB.ServiceAgent);
                    properties.Add("ls", labServer);
                    properties.Add("op", expCoupon);

                    DateTime start = DateTime.UtcNow;
                    duration = 7L * 24L * 60L * 60L; // default is one week
                     RecipeExecutor executor = null;
                    string redirectURL = null;

                    //Create a redeemSession ticket for the experiment
                    //payload includes username and current group name & client id.
                    string sessionPayload = factory.createRedeemSessionPayload(userID, groupID,
                               clientID, userName, groupName);
                    // SB is the redeemer, ticket type : session_identifcation, no expiration time, payload,SB as sponsor ID, redeemer(SB) coupon
                    AddTicket(expCoupon, TicketTypes.REDEEM_SESSION, ProcessAgentDB.ServiceGuid,
                                  ProcessAgentDB.ServiceGuid, duration, sessionPayload);

                   // AdministrativeAPI.ModifyUserSession(Convert.ToInt64(Session["SessionID"]), groupID, clientID, Session.SessionID);

                    if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT)
                    {
                        // execute the "interactive experiment execution recipe
                        executor = RecipeExecutor.Instance();

                        // loaderScript not parsed in Recipe
                        redirectURL = executor.ExecuteExperimentExecutionRecipe(expCoupon, labServer, client,
                         start, duration, userTZ, userID,
                         effectiveGroupID, effectiveGroupName);
                        //Do not add the returnURL

                        // Parse & check that the default auth tokens are added
                        result.tag = parser.Parse(redirectURL, properties, true);
                        result.id = LabClient.INTERACTIVE_BIT | LabClient.REDIRECT_BIT;
                    }

                    else if (client.clientType == LabClient.INTERACTIVE_APPLET)
                    {
                          // execute the "interactive experiment execution recipe
                        executor = RecipeExecutor.Instance();

                        // loaderScript not parsed in Recipe
                        redirectURL = executor.ExecuteExperimentExecutionRecipe(expCoupon, labServer, client,
                         start, duration, userTZ, userID,
                         effectiveGroupID, effectiveGroupName);
                        // Applets do not use default query string parameters, parameters must be in the loader script
                        result.tag = parser.Parse(redirectURL, properties);
                        result.id = LabClient.INTERACTIVE_BIT | LabClient.APPLET_BIT;

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

                    // Support for Batch 6.1 Lab Clients
                    else if (client.clientType == LabClient.BATCH_HTML_REDIRECT)
                    {
                        // use the Loader script for Batch experiments, for now check for default properties
                        result.tag = parser.Parse(client.loaderScript, properties,true);
                        result.id = LabClient.BATCH_BIT | LabClient.REDIRECT_BIT;
                    }
                    // use the Loader script for Batch experiments
                    else if (client.clientType == LabClient.BATCH_APPLET)
                    {
                        // Do not append defaults
                        result.tag = parser.Parse(client.loaderScript, properties);
                        result.id = LabClient.BATCH_BIT | LabClient.APPLET_BIT;
                    }
                } // labserver != null
                else
                {
                    buf.Append(" LabServer = null");
                }

            Logger.WriteLine(buf.ToString());

            ////////////////
            return result;
        }
Пример #17
0
        protected void btnRemoveReservation_Click(object sender, System.EventArgs e)
        {
            DateTime startTime = DateTime.MinValue;
            DateTime endTime = DateTime.MinValue;
            DateTime startTimeUTC = startTime.ToUniversalTime();
            DateTime endTimeUTC = endTime.ToUniversalTime();
            int experimentInfoId = -1;

            if (lbxReservation.SelectedIndex < 0)
            {
                string msg = "Please select the reservation to be removed. ";
                lblErrorMessage.Text = Utilities.FormatWarningMessage(msg);
                lblErrorMessage.Visible = true;
                return;
            }

            try
            {
                int[] resIDs = new int[] { Int32.Parse(lbxReservation.SelectedValue) };
                if (resIDs != null && resIDs.Length > 0)
                {
                    ReservationInfo[] remove = dbManager.GetReservations(resIDs);
                    if (remove != null && remove.Length > 0)
                    {
                        startTimeUTC = remove[0].startTime;
                        endTimeUTC = remove[0].endTime;
                        experimentInfoId = remove[0].experimentInfoId;
                        UssExperimentInfo[] exp = dbManager.GetExperimentInfos(new int[] { remove[0].experimentInfoId });
                        UssCredentialSet[] cSet = dbManager.GetCredentialSets(new int[] { remove[0].credentialSetId });
                        LSSInfo lss = dbManager.GetLSSInfo(exp[0].lssGuid);

                        if (exp != null && exp.Length > 0 && cSet != null && cSet.Length > 0 && lss.lssUrl != null)
                        {
                            Coupon coupon = dbManager.GetCoupon(lss.revokeCouponID, lss.domainGuid);
                            if (coupon != null)
                            {
                                OperationAuthHeader opHeader = new OperationAuthHeader();
                                opHeader.coupon = coupon;
                                LabSchedulingProxy lssProxy = new LabSchedulingProxy();
                                lssProxy.OperationAuthHeaderValue = opHeader;
                                lssProxy.Url = lss.lssUrl;

                                int count = lssProxy.RemoveReservation(cSet[0].serviceBrokerGuid, cSet[0].groupName, ProcessAgentDB.ServiceGuid,
                                    exp[0].labServerGuid, exp[0].labClientGuid, startTimeUTC, endTimeUTC);
                                if (count > 0)
                                {
                                    dbManager.RemoveReservation(resIDs);
                                    string msg = "The reservation has been removed successfully! ";
                                    lblErrorMessage.Text = Utilities.FormatConfirmationMessage(msg);
                                    lblErrorMessage.Visible = true;
                                }
                                else
                                {
                                    string msg = "The reservation has not been removed successfully.";
                                    lblErrorMessage.Text = Utilities.FormatErrorMessage(msg);
                                    lblErrorMessage.Visible = true;
                                }
                            }
                            else
                            {
                                string msg = "Access denied: The reservation has not been removed successfully.";
                                lblErrorMessage.Text = Utilities.FormatErrorMessage(msg);
                                lblErrorMessage.Visible = true;
                            }
                        }
                        buildReservationListBox();
                    }
                }
            }

            catch (Exception ex)
            {
                string msg = "Exception: reservation can not be removed. " + ex.GetBaseException() + ".";
                lblErrorMessage.Text = Utilities.FormatErrorMessage(msg);
                lblErrorMessage.Visible = true;
            }
        }
Пример #18
0
        protected void btnMakeReservation_Click(object sender, System.EventArgs e)
        {
            // ToDo: Add error checking
            DateTime startReserveTime = DateUtil.ParseUserToUtc(ddlSelectTime.SelectedItem.Text, culture, userTZ);
            DateTime endReserveTime = startReserveTime.AddSeconds(Double.Parse(ddlDuration.SelectedValue));
            if ((endReserveTime.Minute % quantum) != 0)
            {
                DateTime dt = endReserveTime.AddMinutes(quantum - (endReserveTime.Minute % quantum));
                if (dt <= endTimePeriod)
                {
                    endReserveTime = dt;
                }
                else
                {
                    endReserveTime = endTimePeriod;
                }
            }
            lblErrorMessage.Text = ddlSelectTime.SelectedItem.Text + " " + DateUtil.ToUserTime(endReserveTime, culture, -userTZ);
            lblErrorMessage.Visible = true;
            string notification = null;
            LabSchedulingProxy lssProxy = new LabSchedulingProxy();
            lssProxy.Url = lssURL;
            try
            {
                // create "REQUEST RESERVATION" ticket in SB and get the coupon for the ticket.
                //iLabs.DataTypes.TicketingTypes.Coupon authCoupon = ticketIssuer.CreateTicket(lssGuid, "REQUEST RESERVATION", 300, "");

                //assign the coupon from ticket to the soap header;
                OperationAuthHeader opHeader = new OperationAuthHeader();
                opHeader.coupon = coupon;
                lssProxy.OperationAuthHeaderValue = opHeader;
                notification = lssProxy.ConfirmReservation(serviceBrokerGuid, groupName, ProcessAgentDB.ServiceGuid, labServerGuid, clientGuid,
                    startReserveTime, endReserveTime);
                if (notification != "The reservation is confirmed successfully")
                {
                    lblErrorMessage.Text = Utilities.FormatErrorMessage(notification);
                }
                else
                {
                    try
                    {
                        int status = USSSchedulingAPI.AddReservation(userName, serviceBrokerGuid, groupName, labServerGuid, clientGuid,
                            startReserveTime, endReserveTime);
                        string confirm = "The reservation from<br />" + DateUtil.ToUserTime(startReserveTime,culture,userTZ)
                            + " to " + DateUtil.ToUserTime(endReserveTime, culture, userTZ) + "<br />is confirmed.";
                        lblErrorMessage.Text = Utilities.FormatConfirmationMessage(confirm);
                    }
                    catch(Exception insertEx){
                        lblErrorMessage.Text = Utilities.FormatErrorMessage(notification);
                        lblErrorMessage.Visible = true;
                    }
                     getTimePeriods();
                }
                lblErrorMessage.Visible = true;
                    return;
            }
            catch (Exception ex)
            {
                string msg = "Exception: reservation can not be confirmed. " + ex.GetBaseException() + ".";
                lblErrorMessage.Text = Utilities.FormatErrorMessage(msg);
                lblErrorMessage.Visible = true;

            }
            try
            {
                if (notification == "The reservation is confirmed successfully")
                {
                    int experimentInfoId = USSSchedulingAPI.ListExperimentInfoIDByExperiment(labServerGuid, clientGuid);
                    DateTime startTimeUTC = startReserveTime.ToUniversalTime();
                    DateTime endTimeUTC = endReserveTime.ToUniversalTime();
                }
                return;
            }
            catch (Exception ex)
            {
                string msg = "Exception: reservation can not be added successfully. " + ex.GetBaseException() + ".";
                lblErrorMessage.Text = Utilities.FormatErrorMessage(msg);
                lblErrorMessage.Visible = true;
                lssProxy.RemoveReservation(serviceBrokerGuid, groupName, ProcessAgentDB.ServiceGuid, labServerGuid, clientGuid, startReserveTime, endReserveTime);
            }
        }
Пример #19
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            int groupID = 0;
            int authID = -1;
            Coupon opCoupon = null;
            string groupName = null;
            lblResponse.Visible = false;

            userTZ = Convert.ToInt32(Session["UserTZ"]);
            culture = DateUtil.ParseCulture(Request.Headers["Accept-Language"]);
            lc = null;
            if (!IsPostBack)
            {
                // retrieve parameters from URL
                couponId = Request.QueryString["coupon_id"];
                passkey = Request.QueryString["passkey"];
                issuerGuid = Request.QueryString["issuer_guid"];
                if (couponId != null && passkey != null && issuerGuid != null)
                {
                    opCoupon = new Coupon(issuerGuid, Int64.Parse(couponId), passkey);
                    Ticket authExperimentTicket = issuer.RetrieveTicket(opCoupon,
                        TicketTypes.CREATE_EXPERIMENT, ProcessAgentDB.ServiceGuid);
                    if (authExperimentTicket != null)
                    {
                        XmlQueryDoc authDoc = new XmlQueryDoc(authExperimentTicket.payload);
                        string auth = authDoc.Query("CreateExperimentPayload/authID");
                        if (auth != null && auth.Length > 0)
                        {
                            authID = Int32.Parse(auth);

                        }
                        string grpName = authDoc.Query("CreateExperimentPayload/groupName");
                        if (grpName != null && groupName.Length > 0)
                        {
                            Session["GroupName"] = grpName;
                            int grpID = AdministrativeAPI.GetGroupID(grpName);
                            if (grpID > 0)
                                Session["GroupID"] = groupID;
                        }
                        string userName = authDoc.Query("CreateExperimentPayload/userName");
                        if (userName != null && userName.Length > 0)
                        {
                            Session["UserName"] = userName;
                            int userID = AdministrativeAPI.GetUserID(userName,authID);
                            if (userID > 0)
                                Session["UserID"] = userID;
                        }
                        string clientGuid = authDoc.Query("CreateExperimentPayload/clientGuid");
                        if (clientGuid != null && clientGuid.Length > 0)
                        {
                            Session["ClientGuid"] = clientGuid;
                            int clientID = AdministrativeAPI.GetLabClientID(clientGuid);
                            if (clientID > 0)
                                Session["ClientID"] = clientID;
                        }
                    }
                }
                pReenter.Visible = false;
                btnReenter.Visible = false;
                auto = Request.QueryString["auto"];
                if (auto != null && auto.Length > 0)
                {
                    if (auto.ToLower().Contains("t"))
                    {
                        autoLaunch = true;
                    }
                }
            }
            if (Session["ClientID"] != null && Session["ClientID"].ToString().Length > 0)
            {
                lc = wrapper.GetLabClientsWrapper(new int[] { Convert.ToInt32(Session["ClientID"]) })[0];
            }
            if (Session["GroupID"] != null && Session["GroupID"].ToString().Length > 0)
            {
                groupID = Convert.ToInt32(Session["GroupID"]);
            }
            if (groupID > 0 && lc != null)
            {
                setEffectiveGroup(groupID, lc.clientID);
            }
            if (Session["GroupName"] != null && Session["GroupName"].ToString().Length > 0)
            {
                groupName = Session["GroupName"].ToString();
                lblGroupNameTitle.Text = groupName;
            }

            if (lc != null)
            {
                labServer = getLabServer(lc.clientID, effectiveGroupID);
                clientInfos = AdministrativeAPI.ListClientInfos(lc.clientID);
                if (lc.clientType == LabClient.INTERACTIVE_APPLET || lc.clientType == LabClient.INTERACTIVE_HTML_REDIRECT)
                {
                    if (lc.needsScheduling)
                    {
                        Ticket allowExperimentExecutionTicket = null;
                        if (opCoupon != null)
                        {
                            // First check for an Allow Execution Ticket
                            allowExperimentExecutionTicket = issuer.RetrieveTicket(
                                opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION);
                        }
                        if (allowExperimentExecutionTicket == null)
                        {
                            // Try for a reservation
                            int ussId = issuer.FindProcessAgentIdForClient(lc.clientID, ProcessAgentType.SCHEDULING_SERVER);
                            if (ussId > 0)
                            {
                                ProcessAgent uss = issuer.GetProcessAgent(ussId);
                                // check for current reservation

                                //create a collection & redeemTicket
                                string redeemPayload = TicketLoadFactory.Instance().createRedeemReservationPayload(DateTime.UtcNow,
                                    DateTime.UtcNow, Session["UserName"].ToString(), Convert.ToInt32(Session["UserID"]),
                                    groupName, lc.clientGuid);
                                if (opCoupon == null)
                                    opCoupon = issuer.CreateCoupon();

                                issuer.AddTicket(opCoupon, TicketTypes.REDEEM_RESERVATION, uss.agentGuid,
                                    ProcessAgentDB.ServiceGuid, 600, redeemPayload);

                                UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                                OperationAuthHeader op = new OperationAuthHeader();
                                op.coupon = opCoupon;
                                ussProxy.Url = uss.webServiceUrl;
                                ussProxy.OperationAuthHeaderValue = op;
                                Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid,
                                    Session["UserName"].ToString(), labServer.agentGuid, lc.clientGuid);
                                if (reservation != null)
                                {
                                    // Find efective group
                                    setEffectiveGroup(groupID, lc.clientID);

                                    // create the allowExecution Ticket
                                    DateTime start = reservation.Start;
                                    long duration = reservation.Duration;
                                    string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload(
                                        start, duration, effectiveGroupName,lc.clientGuid);
                                    DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond);
                                    DateTime utcNow = DateTime.UtcNow;
                                    long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond;
                                    allowExperimentExecutionTicket = issuer.AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION,
                                            ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload);
                                }
                            }
                        }
                        if (allowExperimentExecutionTicket != null)
                        {
                            XmlDocument payload = new XmlDocument();
                            payload.LoadXml(allowExperimentExecutionTicket.payload);
                            startExecution = DateUtil.ParseUtc(payload.GetElementsByTagName("startExecution")[0].InnerText);
                            duration = Int64.Parse(payload.GetElementsByTagName("duration")[0].InnerText);

                            Session["StartExecution"] = DateUtil.ToUtcString(startExecution);
                            Session["Duration"] = duration;

                            // Display reenter button if experiment is reentrant & a current experiment exists
                            if (lc.IsReentrant)
                            {

                                long[] ids = InternalDataDB.RetrieveActiveExperimentIDs(Convert.ToInt32(Session["UserID"]),
                                    effectiveGroupID, labServer.agentId, lc.clientID);
                                if (ids.Length > 0)
                                {
                                    btnLaunchLab.Text = "Launch New Experiment";
                                   btnLaunchLab.OnClientClick = "javascript:return confirm('Are you sure you want to start a new experiment?\\n If you proceed the currently running experimnent will be closed.');";
                                    btnLaunchLab.Visible = true;
                                    pLaunch.Visible = true;
                                    pReenter.Visible = true;
                                    btnReenter.Visible = true;
                                    btnReenter.CommandArgument = ids[0].ToString();
                                }
                                else
                                {

                                    //pReenter.Visible = false;
                                    //btnReenter.Visible = false;
                                    btnLaunchLab.Text = "Launch Lab";
                                    btnLaunchLab.OnClientClick="";
                                    if (autoLaunch)
                                    {
                                        launchLabClient(lc.clientID);
                                    }
                                    else
                                    {
                                        pLaunch.Visible = true;
                                        btnLaunchLab.Visible = true;
                                    }
                                }
                            }
                            else
                            {
                                pLaunch.Visible = true;
                                btnLaunchLab.Visible = true;
                                btnLaunchLab.OnClientClick = "";
                                if (autoLaunch)
                                {
                                    launchLabClient(lc.clientID);
                                }
                            }
                        }
                        else
                        {
                            pLaunch.Visible = false;
                            btnLaunchLab.Visible = false;
                        }
                    }
                    else
                    {
                        pLaunch.Visible = true;
                        btnLaunchLab.Visible = true;
                        if (autoLaunch)
                        {
                            launchLabClient(lc.clientID);
                        }
                    }
                }
                else if (lc.clientType == LabClient.BATCH_APPLET || lc.clientType == LabClient.BATCH_HTML_REDIRECT)
                {
                    pLaunch.Visible = true;
                    btnLaunchLab.Visible = true;
                    if (autoLaunch)
                    {
                        launchLabClient(lc.clientID);
                    }

                }
                btnSchedule.Visible = lc.needsScheduling;
                lblClientName.Text = lc.clientName;
                lblVersion.Text = lc.version;
                lblLongDescription.Text = lc.clientLongDescription;
                if (lc.notes != null && lc.notes.Length > 0)
                {
                    pNotes.Visible = true;
                    lblNotes.Text = lc.notes;
                }
                else
                {
                    pNotes.Visible = false;
                    lblNotes.Text = null;
                }
                if (lc.contactEmail != null && lc.contactEmail.Length > 0)
                {
                    pEmail.Visible = true;
                    string emailCmd = "mailto:" + lc.contactEmail;
                    lblEmail.Text = "<a href=" + emailCmd + ">" + lc.contactEmail + "</a>";
                }
                else
                {
                    pEmail.Visible = false;
                    lblEmail.Text = null;
                }
                if (lc.documentationURL != null && lc.documentationURL.Length > 0)
                {
                    pDocURL.Visible = true;
                    lblDocURL.Text = "<a href=" + lc.documentationURL + ">" + lc.documentationURL + "</a>";
                }
                else
                {
                    pDocURL.Visible = false;
                    lblDocURL.Text = null;
                }

                btnLaunchLab.Command += new CommandEventHandler(this.btnLaunchLab_Click);
                btnLaunchLab.CommandArgument = lc.clientID.ToString();

                int count = 0;

                if (clientInfos != null && clientInfos.Length > 0)
                {
                    //repClientInfos.DataSource = clientInfos;
                    //repClientInfos.DataBind();
                    foreach (ClientInfo ci in clientInfos)
                    {
                        System.Web.UI.WebControls.Button b = new System.Web.UI.WebControls.Button();
                        b.Visible = true;
                        b.CssClass = "button";
                        b.Text = ci.infoURLName;
                        b.CommandArgument = ci.infoURL;
                        b.CommandName = ci.infoURLName;
                        b.ToolTip = ci.description;
                        b.Command += new CommandEventHandler(this.HelpButton_Click);
                        repClientInfos.Controls.Add(b);
                        repClientInfos.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
                    }
                }
            }
            else
            {
                // No LabClient
                btnSchedule.Visible = false;
                pLaunch.Visible = false;
                btnLaunchLab.Visible = false;
                string msg = "There are no labs assigned to group: " + Session["GroupName"].ToString() + "!";
                lblResponse.Text = Utilities.FormatErrorMessage(msg);
                lblResponse.Visible = true;
            }
            // System_Messages block

            SystemMessage[] groupMessages = null;
            SystemMessage[] serverMessages = null;
            groupMessages = AdministrativeAPI.SelectSystemMessagesForGroup(Convert.ToInt32(Session["GroupID"]));
            if (lc != null && labServer != null && labServer.agentId > 0)
            {
                serverMessages = wrapper.GetSystemMessagesWrapper(SystemMessage.LAB, 0, 0, labServer.agentId);
            }
            if ((groupMessages == null || groupMessages.Length == 0) && (serverMessages == null || serverMessages.Length == 0))
            {

                lblGroupNameSystemMessage.Text = "No Messages at this time!";
                lblGroupNameSystemMessage.Visible = true;
                lblServerSystemMessage.Visible = false;
            }
            else
            {
                if (groupMessages != null && groupMessages.Length > 0)
                {
                    lblGroupNameSystemMessage.Text = "Group Messages:";
                    lblGroupNameSystemMessage.Visible = true;
                    repGroupMessage.DataSource = groupMessages;
                    repGroupMessage.DataBind();
                }
                else
                {
                    lblGroupNameSystemMessage.Visible = false;
                }

                if (serverMessages != null && serverMessages.Length > 0)
                {
                    lblServerSystemMessage.Text = "Client/Server Messages:";
                    lblServerSystemMessage.Visible = true;
                    repServerMessage.DataSource = serverMessages;
                    repServerMessage.DataBind();
                }
                else
                {
                    lblServerSystemMessage.Visible = false;
                }
            }
        }