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

        /// <summary>Returns an instance of a ComputingResource subclass representing the computing resource with the specified identifier.</summary>
        /// <param name="context">The execution environment context.</param>
        /// <param name="identifier">The unique identifier of the computing resource.</param>
        /// <returns>The created ComputingResource subclass instance.</returns>
        public static ComputingResource FromIdentifier(IfyContext context, string identifier)
        {
            EntityType        entityType = EntityType.GetEntityType(typeof(ComputingResource));
            ComputingResource result     = (ComputingResource)entityType.GetEntityInstanceFromIdentifier(context, identifier);

            result.Identifier = identifier;
            result.Load();
            return(result);
        }
Пример #2
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Returns an instance of a ComputingResource subclass representing the computing resource with the specified database ID.</summary>
        /// <param name="context">The execution environment context.</param>
        /// <param name="id">The database ID of the computing resource.</param>
        /// <returns>The created ComputingResource subclass instance.</returns>
        public static ComputingResource FromId(IfyContext context, int id)
        {
            EntityType        entityType = EntityType.GetEntityType(typeof(ComputingResource));
            ComputingResource result     = (ComputingResource)entityType.GetEntityInstanceFromId(context, id);

            result.Id = id;
            result.Load();
            return(result);
        }
Пример #3
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Returns an instance of a ComputingResource subclass representing the computing resource with the specified ID, address or caption.</summary>
        /// <param name="context">The execution environment context.</param>
        /// <param name="s">A search value that must match the database ID (preferred) of the computing resource, or its unique identifier.</param>
        /// <returns>The created ComputingResource subclass instance.</returns>
        public static ComputingResource FromString(IfyContext context, string s)
        {
            int id = 0;

            Int32.TryParse(s, out id);
            EntityType        entityType = EntityType.GetEntityType(typeof(ComputingResource));
            ComputingResource result     = (ComputingResource)entityType.GetEntityInstanceFromCondition(context, String.Format("t.name={0} OR t.id={1}", StringUtils.EscapeSql(s), id), String.Format("t.id!={0}", id));

            result.Id   = id;
            result.Name = s;
            result.Load();
            return(result);
        }
Пример #4
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();
        }
        public override object GetFilterForParameter(string parameter, string value)
        {
            switch (parameter)
            {
            case "available":
                switch (value)
                {
                case "all":
                    return(new KeyValuePair <string, string>());

                case "false":
                    return(new KeyValuePair <string, string>("Available", "false"));

                case "true":
                default:
                    return(new KeyValuePair <string, string>("Available", "true"));
                }

            case "cat":
                switch (value)
                {
                case "commercial":
                    return(new KeyValuePair <string, string>("Commercial", "true"));

                case "!commercial":
                    return(new KeyValuePair <string, string>("Commercial", "false"));

                default:
                    return(new KeyValuePair <string, string>());
                }

            case "cr":
                try {
                    var p = ComputingResource.FromIdentifier(context, value);
                    return(new KeyValuePair <string, string>("ProviderId", p.Id + ""));
                } catch (Exception e) {
                    return(new KeyValuePair <string, string>("ProviderId", "-1"));
                }

            case "version":
                return(new KeyValuePair <string, string>("Version", value));

            default:
                return(base.GetFilterForParameter(parameter, value));
            }
        }