Пример #1
0
        //---------------------------------------------------------------------------------------------------------------------

        public static void SetAccountStatus(IfyContext context, int[] ids, int accountStatus)
        {
            if (context.AccessLevel != EntityAccessLevel.Administrator)
            {
                throw new EntityUnauthorizedException("You are not authorized to enable or disable user accounts", null, null, 0);
            }
            string idsStr = "";

            for (int i = 0; i < ids.Length; i++)
            {
                idsStr += (idsStr == "" ? "" : ",") + ids[i];
            }
            string sql = String.Format("UPDATE usr SET status={0}{1} WHERE id{2};",
                                       accountStatus.ToString(),
                                       accountStatus == AccountStatusType.Enabled ? ", failed_logins=0" : String.Empty,
                                       ids.Length == 1 ? "=" + idsStr : " IN (" + idsStr + ")"
                                       );
            int count = context.Execute(sql);

            if (count > 0)
            {
                context.WriteInfo(count + " user account" + (count == 1 ? " was " : "s were ") + (accountStatus == AccountStatusType.Enabled ? "enabled" : "disabled"));
            }
            else
            {
                context.WriteWarning("No user account has been " + (accountStatus == AccountStatusType.Enabled ? "enabled" : "disabled"));
            }
            //OnItemProcessed(OperationType.Other, 0); // TODO
        }
Пример #2
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Executes the scheduler-related part of the background agent action <b>%Task&nbsp;and&nbsp;scheduler&nbsp;cleanup</b>.</summary>

        /*
         *  This method is called periodically if the action is active and the background agent is running according to the action's execution interval specified in the portal configuration.
         *
         *  The background agent action <b>%Task&nbsp;cleanup</b> deletes the tasks that have been marked for deletion and no longer consume Grid engine resources, together with all data related to these tasks (jobs, node information etc.), from the database.
         *  This is the case for tasks that have the value <i>Deleted</i> in the database field <i>task.status</i>.
         *  %Tasks deletions are pending if they were requested while the portal configuration variable <i>SynchronousTaskOperations</i> was set to <i>false</i>.
         *
         * /// <param name="context">The execution environment context.</param>
         * /// \xrefitem rmodp "RM-ODP" "RM-ODP Documentation"
         */
        public static void ExecuteCleanup(IfyContext context)
        {
            IDataReader reader;
            List <int>  schedulerIds = new List <int>();

            // Abort tasks (next_status = Deleted)
            reader = context.GetQueryResult(String.Format("SELECT t.id FROM scheduler AS t WHERE status={0} ORDER BY t.id;", ProcessingStatus.Deleted));
            while (reader.Read())
            {
                schedulerIds.Add(reader.GetInt32(0));
            }
            reader.Close();

            int count = 0, taskCount = 0;

            foreach (int schedulerId in schedulerIds)
            {
                Scheduler scheduler = FromId(context, schedulerId);
                taskCount += scheduler.DoAbortAllTasks();
                context.Execute(String.Format("DELETE FROM scheduler WHERE id={0};", schedulerId));
                count++;
            }
            schedulerIds.Clear();

            if (count > 0)
            {
                context.WriteInfo(String.Format("Deleted schedulers {0}: (aborted tasks: {1})", count, taskCount));
            }
        }
Пример #3
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Executes the background agent action <b>Computing&nbsp;Element&nbsp;status&nbsp;refresh</b>.</summary>
        /// <param name="context">The execution environment context.</param>
        /// <remarks>
        ///     <p>This method is called periodically if the action is active and the background agent is running according to the action's execution interval specified in the portal configuration.</p>
        ///     <p>The background agent action <b>Computing&nbsp;Element&nbsp;status&nbsp;refresh</b> refreshes task, job and node status information for active tasks.</p>
        /// </remarks>
        public static void ExecuteComputingResourceStatusRefresh(IfyContext context)
        {
            IDataReader       reader;
            ComputingResource computingResource;
            List <int>        computingResourceIds = new List <int>();
            int unknownCount = 0;

            // Add computing resources into status table if not yet there
            context.Execute("INSERT INTO crstate (id_cr) SELECT id FROM cr AS t LEFT JOIN crstate AS t1 ON t.id=t1.id_cr WHERE t1.id_cr IS NULL;");

            // Get computing resources with actual status Active (10)
            reader = null;
            string        sql          = "SELECT t.id FROM ce AS t WHERE status_method IS NOT NULL ORDER BY t.id;"; // WHERE status=" + ProcessingStatus.Active + " AND remote_id IS NOT NULL ORDER BY t.id;";
            IDbConnection dbConnection = context.GetDbConnection();

            reader = context.GetQueryResult(sql, dbConnection);
            while (reader.Read())
            {
                computingResourceIds.Add(reader.GetInt32(0));
            }
            context.CloseQueryResult(reader, dbConnection);

            //context.WriteInfo(String.Format("Active tasks: {0}{1}", computingResourceIds.Count, computingResourceIds.Count == 0 ? String.Empty : " - status display format: created/active/failed/incomplete/completed"));
            // Get available computing resource information
            for (int i = 0; i < computingResourceIds.Count; i++)
            {
                computingResource = ComputingResource.FromId(context, computingResourceIds[i]);
                //computingResource.Restricted = false;
                computingResource.GetStatus();

                if (computingResource.Refreshed)
                {
                    context.WriteInfo(
                        String.Format("{0}: total: {1}, free: {2}",
                                      computingResource.Name,
                                      computingResource.TotalCapacity,
                                      computingResource.FreeCapacity
                                      )
                        );
                }
                else
                {
                    unknownCount++;
                }
            }
            if (unknownCount != 0)
            {
                context.WriteWarning(String.Format("Computing resources with unavailable status: {0} (out of {1})", unknownCount, computingResourceIds.Count));
            }
            computingResourceIds.Clear();
        }
Пример #4
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Performs the background action for the password expiration check.</summary>
        /// <param name="context">The execution environment context.</param>
        /// <remarks>
        ///     The background agent action <em>Password expiration check</em> deactivates user accounts for which the password has not been set for longer than the password expiration time (see <see cref="PasswordExpireTime"/>.
        ///     Users can still use their accounts after setting a new password.
        /// </remarks>
        public static void ExecutePasswordExpirationCheck(IfyContext context)
        {
            if (context.DebugLevel >= 3)
            {
                context.WriteDebug(3, "PasswordExpireTime seconds: " + passwordExpireTime);
            }

            if (passwordExpireTime <= 0)
            {
                return;
            }
            DateTime earliestTime = context.Now.AddSeconds(-passwordExpireTime);

            string sql = String.Format("UPDATE usr SET status={0} WHERE status={1} AND allow_password AND (last_password_change_time IS NULL OR last_password_change_time<'{2}');", AccountStatusType.Deactivated, AccountStatusType.Enabled, earliestTime.ToString(@"yyyy\-MM\-dd HH\:mm\:ss"));

            context.WriteDebug(3, sql);
            int count = context.Execute(sql);

            context.WriteInfo("Deactivated user accounts: " + (count <= 0 ? "0" : count.ToString()));
        }
Пример #5
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Queries the catalogue and receives the data sets to build the result.</summary>
        /// <param name="minCount">Minimum number of data sets to be included. If the minimum number is not reached, the result will be empty.</param>
        /// <param name="maxCount">Maxium number of data sets to be included.</param>
        public void GetDataSets(int minCount, int maxCount)
        {
            this.minCount = minCount;
            this.maxCount = maxCount;

            if (Url != null)
            {
                // Get the element names from the configuration file
                XmlDocument configDoc     = new XmlDocument();
                XmlElement  catalogueElem = null;
                bool        success       = false;
                try {
                    configDoc.Load(context.SiteConfigFolder + "/services.xml");
                    success = ((catalogueElem = configDoc.SelectSingleNode("/services/dataset/catalogue[@type='application/rdf+xml']") as XmlElement) != null);
                } catch (Exception) {
                }

                if (success)
                {
                    for (int i = 0; i < catalogueElem.ChildNodes.Count; i++)
                    {
                        XmlElement elem = catalogueElem.ChildNodes[i] as XmlElement;
                        if (elem == null || !elem.HasAttribute("name"))
                        {
                            continue;
                        }
                        switch (elem.Attributes["name"].Value)
                        {
                        case "dataset":
                            DataSetXmlName = elem.InnerXml;
                            break;

                        case "value":
                            ResourceXmlName = elem.InnerXml;
                            break;

                        case "_identifier":
                            IdentifierXmlName = elem.InnerXml;
                            break;

                        case "_size":
                            SizeXmlName = elem.InnerXml;
                            break;
                        }
                    }
                }
                else if (context.UserLevel == UserLevel.Administrator)
                {
                    context.AddWarning("Invalid catalogue metadata configuration");
                }

                // Get first result
                context.AddDebug(2, "Catalogue query (base): " + Url);
                if (!AddResultsFromRdf(Url, 0, (maxCount > ResultsPerRequest ? ResultsPerRequest : maxCount)))
                {
                    context.WriteInfo(String.Format("Return 1"));
                    return;
                }

                if (maxCount == 0 || TotalResults < minCount)
                {
                    InitializeData(0);
                    return;
                }

                // If necessary, do more requests
                if (maxCount > TotalResults)
                {
                    maxCount = TotalResults;
                }
                while (ReceivedResults < maxCount)
                {
                    if (!AddResultsFromRdf(Url, ReceivedResults, (maxCount > ReceivedResults + ResultsPerRequest ? ResultsPerRequest : maxCount - ReceivedResults)))
                    {
                        break;
                    }
                }
                context.AddDebug(2, "Catalogue results: " + ReceivedResults + " (total results: " + TotalResults + ")");
            }
            else if (DataSetParameter != null && context is IfyWebContext)
            {
                TotalResults    = DataSetParameter.Values.Length;
                ReceivedResults = TotalResults;

                InitializeData(ReceivedResults);

                string[] paramValues;
                paramValues = StringUtils.Split((context as IfyWebContext).GetParamValue(DataSetParameter.Name + ":_identifier"), DataSetParameter.Separator);
                if (paramValues.Length == ReceivedResults)
                {
                    for (int i = 0; i < ReceivedResults; i++)
                    {
                        DataSetIdentifiers[i] = paramValues[i];
                    }
                }
                paramValues = StringUtils.Split((context as IfyWebContext).GetParamValue(DataSetParameter.Name + ":_size"), DataSetParameter.Separator);
                if (paramValues.Length == ReceivedResults)
                {
                    for (int i = 0; i < ReceivedResults; i++)
                    {
                        Int64.TryParse(paramValues[i], out DataSetSizes[i]);
                    }
                }

                /*for (int i = 0; i < dataSetTotalCount; i++) DataSets[i] = new DataSetInfo(this, i, DataSetParameter.Values[i], sizes[i], startTimes[i], endTimes[i]); */

                for (int i = 0; i < ReceivedResults; i++)
                {
                    DataSets[i]         = new CatalogueDataSetInfo(this, i);
                    DataSetResources[i] = DataSetParameter.Values[i];
                }

                foreach (KeyValuePair <string, string> kvp in MetadataElementNames)
                {
                    metadataValues[kvp.Key] = new TypedValue[ReceivedResults];
                    paramValues             = StringUtils.Split((context as IfyWebContext).GetParamValue(DataSetParameter.Name + ":" + kvp.Key), DataSetParameter.Separator);
                    if (paramValues.Length == ReceivedResults)
                    {
                        for (int i = 0; i < ReceivedResults; i++)
                        {
                            SetMetadataValue(i, kvp.Key, paramValues[i]);
                        }
                    }
                }

                /*string paramValue = context.GetParamValue(paramName);
                 * datasetParam
                 * string[] paramValues = StringUtils.Split(paramValue, ';');
                 * DataSets = new DataSetInfo[];
                 * int[] fileSizes;
                 * DateTime[] startDates;
                 * DateTime[] endDates;*/
            }
        }