Example #1
0
        public StorageStatus GetExperimentStatus(long experimentId)
        {
            StorageStatus status = new StorageStatus();
            Coupon opCoupon = new Coupon(opHeader.coupon.issuerGuid, opHeader.coupon.couponId,
                 opHeader.coupon.passkey);
            try
            {
                Ticket retrievedTicket = dbTicketing.RetrieveAndVerify(opCoupon, TicketTypes.RETRIEVE_RECORDS);

                    status = experimentsAPI.GetExperimentStatus(experimentId, opCoupon.issuerGuid);

                return status;
            }
            catch
            {
                throw;
            }
        }
Example #2
0
        public StorageStatus SetExperimentStatus(long experimentId, int statusCode)
        {
            StorageStatus status = new StorageStatus();
            Coupon opCoupon = new Coupon(opHeader.coupon.issuerGuid, opHeader.coupon.couponId,
                 opHeader.coupon.passkey);

            try
            {
                Ticket retrievedTicket = null;
                try
                {
                    retrievedTicket = dbTicketing.RetrieveAndVerify(opCoupon, TicketTypes.ADMINISTER_EXPERIMENT);
                }
                catch (TicketExpiredException expEx)
                {
                    if (statusCode < StorageStatus.CLOSED)
                        throw;
                }
                catch (TicketNotFoundException nfEx)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw;
                }

                if ((statusCode & StorageStatus.CLOSED) == StorageStatus.CLOSED)
                    {
                        status = experimentsAPI.GetExperimentStatus(experimentId, opCoupon.issuerGuid);
                        if((status.status & StorageStatus.CLOSED) != StorageStatus.CLOSED)
                            experimentsAPI.CloseExperiment(experimentId, opCoupon.issuerGuid, statusCode);
                        status = experimentsAPI.GetExperimentStatus(experimentId, opCoupon.issuerGuid);
                    }
                    else
                    {
                        status = experimentsAPI.SetExperimentStatus(experimentId, opCoupon.issuerGuid, statusCode);
                    }

                return status;
            }
            catch(Exception ex)
            {
                Utilities.WriteLog("SetExperimentStatuus: " + ex.Message);
                throw;
            }
        }
Example #3
0
        public static bool UpdateExperimentStatus(StorageStatus status)
        {
            bool ok = false;
            DbConnection myConnection = FactoryDB.GetConnection();
            DbCommand myCommand = FactoryDB.CreateCommand("UpdateExperimentStatus", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand, "@experimentID", status.experimentId, DbType.Int64));
            myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand, "@status", status.status, DbType.Int32));
            if (status.closeTime != null && (status.closeTime > MinDbDateTime))
            {
                myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand,"@closeTime", status.closeTime, DbType.DateTime));
            }
            else
            {
                myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand,"@closeTime", null, DbType.DateTime));
            }
            if (status.recordCount != null)
                myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand, "@recordCount",status.recordCount, DbType.Int32));
            else
                myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand, "@recordCount",null, DbType.Int32));

            try
            {
                myConnection.Open();
                myCommand.ExecuteNonQuery();
                ok = true;
            }
            catch (Exception e)
            {
                Utilities.WriteLog("UpdateExperimentStatus: " + e.Message);
            }
            finally
            {
                myConnection.Close();
            }
            return ok;
        }
 public static bool UpdateExperimentStatus(StorageStatus status)
 {
     return InternalDataDB.UpdateExperimentStatus(status);
 }
        public static StorageStatus RetrieveExperimentStatus(long experimentId)
        {
            ExperimentSummary summary = RetrieveExperimentSummary(experimentId);
            if (summary != null)
            {
                StorageStatus status = new StorageStatus();
                status.experimentId = experimentId;
                status.closeTime = summary.closeTime;
                status.creationTime = summary.creationTime;
                status.experimentId = experimentId;
                status.issuerGuid = summary.serviceBrokerGuid;
                status.recordCount = summary.recordCount;
                status.status = summary.status;
                return status;

            }
            else
            {
                return null;
            }
        }
Example #6
0
        public StorageStatus GetExperimentStatus(DbConnection connection, long experimentID, string guid)
        {
            StorageStatus status = null;

            try
            {
                DbCommand myCommand = FactoryDB.CreateCommand("GetExperimentStatus", connection);
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand, "@experimentId", experimentID, DbType.Int64));
                myCommand.Parameters.Add(FactoryDB.CreateParameter(myCommand, "@issuerGuid", guid, DbType.AnsiString,50));
                DbDataReader reader = myCommand.ExecuteReader();
                while (reader.Read())
                {
                    status = new StorageStatus();

                    status.experimentId = reader.GetInt64(0);
                    status.status = reader.GetInt32(1);
                    status.recordCount = reader.GetInt32(2);
                    if (!reader.IsDBNull(3))
                        status.creationTime = DateUtil.SpecifyUTC(reader.GetDateTime(3));
                    if (!reader.IsDBNull(4))
                        status.closeTime = DateUtil.SpecifyUTC(reader.GetDateTime(4));
               ;
                    if (!reader.IsDBNull(5))
                        status.lastModified = DateUtil.SpecifyUTC(reader.GetDateTime(5));
                    status.issuerGuid = reader.GetString(6);
                }
                reader.Close();

            }
            catch (Exception e)
            {
                Utilities.WriteLog("GetExperimentStatus: " + e.Message);
                throw;
            }

            return status;
        }
Example #7
0
        public ClientSubmissionReport Submit(string labServerID, string experimentSpecification, int priorityHint, bool emailNotification)
        {
            // Default to 24 hours duration
            long duration = TimeSpan.TicksPerDay/TimeSpan.TicksPerSecond;
            int seqNo = 0;
            ClientSubmissionReport clientSReport = null;
            try{

                // Checking if user has permission to use the lab server. The method will set headers for lab server calls
                //if authorization is successful.
                CheckAndSetLSAuthorization(labServerID);

                //Retrieve variables from session
                int userID = Convert.ToInt32(Session["UserID"]);
                int effectiveGroupID = Convert.ToInt32(Session["GroupID"]);
                int clientID = 0;
                if (Session["ClientID"] != null )
                    clientID = Convert.ToInt32(Session["ClientID"]);
                string effectiveGroup = Session["GroupName"].ToString();

                ProcessAgentInfo infoLS = dbTicketing.GetProcessAgentInfo(labServerID);
                if (infoLS.retired)
                {
                    throw new Exception("The Batch Lab Server is retired");
                }
                // get qualifier ID of labServer
                int qualifierID = AuthorizationAPI.GetQualifierID(infoLS.agentId, Qualifier.labServerQualifierTypeID);

                /* End collecting information */

                // Checking if user has permission to use the lab server
                if (!AuthorizationAPI.CheckAuthorization(userID, Function.useLabServerFunctionType, qualifierID))
                {
                    // check fails

                    throw new AccessDeniedException("Access denied using labServer '" + infoLS.agentName + "'.");
                }
                else
                {
                    int[] groupIDs = new int[1];
                    groupIDs[0] = effectiveGroupID;

                    SubmissionReport sReport = new SubmissionReport();

                    clientSReport = new ClientSubmissionReport();
                    clientSReport.vReport = new ValidationReport();
                    clientSReport.wait = new WaitEstimate();

                    BrokerDB brokerDB = new BrokerDB();
                    // 1. Create Coupon for ExperimentCollection
                    Coupon coupon = brokerDB.CreateCoupon();

                    int essID = brokerDB.FindProcessAgentIdForClient(clientID, ProcessAgentType.EXPERIMENT_STORAGE_SERVER);
                    //
                    // 2. create ServiceBroker experiment record and get corresponding experiment id
                    // This checks authorization.
                    long experimentID = wrapper.CreateExperimentWrapper(StorageStatus.INITIALIZED, userID, effectiveGroupID, infoLS.agentId, clientID,
                        essID, DateTime.UtcNow, duration);

                    // Store a record of the Experiment Collection Coupon
                    DataStorageAPI.InsertExperimentCoupon(experimentID, coupon.couponId);

                    //3.A create ESS administer experiment ticket, Add 10 minutes to duration
                    // This must be created before the ESS experiment records may be created
                    ProcessAgentInfo essAgent = brokerDB.GetProcessAgentInfo(essID);
                    if (essAgent.retired)
                    {
                        throw new Exception("The Batch Lab Server is retired");
                    }
                    TicketLoadFactory factory = TicketLoadFactory.Instance();

                    brokerDB.AddTicket(coupon,
                           TicketTypes.ADMINISTER_EXPERIMENT, essAgent.AgentGuid, ProcessAgentDB.ServiceGuid, duration, factory.createAdministerExperimentPayload(experimentID, essAgent.webServiceUrl));

                    //3.B create store record ticket, in the MergedSB the records are all saved via the serviceBroker
                    brokerDB.AddTicket(coupon,
                           TicketTypes.STORE_RECORDS, essAgent.agentGuid, ProcessAgentDB.ServiceGuid, duration, factory.StoreRecordsPayload(true, experimentID, essAgent.webServiceUrl));

                    //3.C create retrieve experiment ticket, retrieve Experiment Records never expires, unless experiment deleted
                    //    This should be changed to a long but finite period once eadExisting Expermint is in place.
                    brokerDB.AddTicket(coupon,
                           TicketTypes.RETRIEVE_RECORDS, essAgent.agentGuid, ProcessAgentDB.ServiceGuid, -1, factory.RetrieveRecordsPayload(experimentID, essAgent.webServiceUrl));

                    // 3.D Create the ESS Experiment Records
                    ExperimentStorageProxy ess = new ExperimentStorageProxy();
                    ess.AgentAuthHeaderValue = new AgentAuthHeader();
                    ess.AgentAuthHeaderValue.coupon = essAgent.identOut;
                    ess.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                    ess.OperationAuthHeaderValue = new OperationAuthHeader();
                    ess.OperationAuthHeaderValue.coupon = coupon;
                    ess.Url = essAgent.webServiceUrl;

                    // Call the ESS to create the ESS Records and open the experiment
                    StorageStatus status = ess.OpenExperiment(experimentID, duration);
                    if (status != null)
                        DataStorageAPI.UpdateExperimentStatus(status);

                    seqNo = ess.AddRecord(experimentID, ProcessAgentDB.ServiceGuid,
                              BatchRecordType.SPECIFICATION, true, experimentSpecification, null);

                    // save lab configuration
                    string labConfiguration = batchLS_Proxy.GetLabConfiguration(effectiveGroup);
                    seqNo = ess.AddRecord(experimentID, labServerID,
                        BatchRecordType.LAB_CONFIGURATION, true, labConfiguration, null);

                    // call labServer submit
                    sReport = batchLS_Proxy.Submit(Convert.ToInt32(experimentID), experimentSpecification, effectiveGroup, priorityHint);

                    // save submission report
                    //wrapper.SaveSubmissionReportWrapper(experimentID, sReport);
                    if (sReport.vReport != null)
                        if ((sReport.vReport.errorMessage != null) && (sReport.vReport.errorMessage.CompareTo("") != 0))
                        {
                            seqNo = ess.AddRecord(experimentID, labServerID, BatchRecordType.VALIDATION_ERROR, false, sReport.vReport.errorMessage, null);

                        }

                    if (sReport.vReport.warningMessages != null)
                        foreach (string s in sReport.vReport.warningMessages)
                        {
                            if ((s != null) && (s.CompareTo("") != 0))
                                seqNo = ess.AddRecord(experimentID, labServerID, BatchRecordType.VALIDATION_WARNING, false, s, null);
                        }

                    // return clientSubmissionReport
                    if (sReport.vReport != null)
                    {
                        clientSReport.vReport.accepted = sReport.vReport.accepted;
                        clientSReport.vReport.errorMessage = sReport.vReport.errorMessage;
                        // if error exists then change status to "an experiment with a problem"
                        if ((sReport.vReport.errorMessage != null) && (!sReport.vReport.errorMessage.Equals("")))
                        {
                            StorageStatus sStatus = new StorageStatus();
                            sStatus.experimentId = experimentID;
                            //sStatus.estRuntime=sReport.vReport.estRuntime;
                            sStatus.status = StorageStatus.BATCH_TERMINATED_ERROR;
                            DataStorageAPI.UpdateExperimentStatus(sStatus);
                        }
                        clientSReport.vReport.estRuntime = sReport.vReport.estRuntime;
                        clientSReport.vReport.warningMessages = sReport.vReport.warningMessages;
                    }
                    clientSReport.experimentID = Convert.ToInt32(experimentID);
                    clientSReport.minTimeToLive = sReport.minTimetoLive;
                    if (sReport.wait != null)
                    {
                        clientSReport.wait.effectiveQueueLength = sReport.wait.effectiveQueueLength;
                        clientSReport.wait.estWait = sReport.wait.estWait;
                    }
                }

                return clientSReport;
            }

            catch
            {
                throw;
            }
        }