public bool UpdateOrCreateIfLatest(FunctionSnapshot snapshot, string currentETag, DateTimeOffset currentVersion)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            StoreItem existing = _store.Where(i => i.FunctionSnapshot.Id == snapshot.Id).FirstOrDefault();

            if (existing == null)
            {
                _store.Add(CreateStoreItem(snapshot));
                return true;
            }
            else if (currentETag == existing.ETag && currentVersion < snapshot.HostVersion)
            {
                Debug.Assert(currentVersion == existing.FunctionSnapshot.HostVersion);
                _store.Remove(existing);
                _store.Add(CreateStoreItem(snapshot));
                return true;
            }
            else
            {
                // Tell callers when they have the latest version, even if it was already present.
                return existing.FunctionSnapshot.HostVersion == snapshot.HostVersion;
            }
        }
        public Guid TriggerAndOverride(string queueName, FunctionSnapshot function,
            IDictionary<string, string> arguments, Guid? parentId, ExecutionReason reason)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            Guid id = Guid.NewGuid();

            CallAndOverrideMessage message = new CallAndOverrideMessage
            {
                Id = id,
                FunctionId = function.HostFunctionId,
                Arguments = arguments,
                ParentId = parentId,
                Reason = reason
            };

            string functionId = new FunctionIdentifier(function.QueueName, function.HostFunctionId).ToString();
            FunctionInstanceSnapshot snapshot = CreateSnapshot(id, arguments, parentId, DateTimeOffset.UtcNow,
                functionId, function.FullName, function.ShortName);

            _logger.LogFunctionQueued(snapshot);
            _sender.Enqueue(queueName, message);

            return id;
        }
示例#3
0
        public bool CreateOrUpdateIfLatest(FunctionSnapshot snapshot)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            return(_store.CreateOrUpdateIfLatest(snapshot.Id, snapshot.HostVersion, CreateOtherMetadata(snapshot), snapshot));
        }
        public bool CreateOrUpdateIfLatest(FunctionSnapshot snapshot)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            return _store.CreateOrUpdateIfLatest(snapshot.Id, snapshot.HostVersion, CreateOtherMetadata(snapshot), snapshot);
        }
        public bool UpdateOrCreateIfLatest(FunctionSnapshot snapshot, string currentETag, DateTimeOffset currentVersion)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            return _store.UpdateOrCreateIfLatest(snapshot.Id, snapshot.HostVersion, CreateOtherMetadata(snapshot),
                snapshot, currentETag, currentVersion);
        }
示例#6
0
        public bool UpdateOrCreateIfLatest(FunctionSnapshot snapshot, string currentETag, DateTimeOffset currentVersion)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            return(_store.UpdateOrCreateIfLatest(snapshot.Id, snapshot.HostVersion, CreateOtherMetadata(snapshot),
                                                 snapshot, currentETag, currentVersion));
        }
        public static IDictionary<string, string> CreateOtherMetadata(FunctionSnapshot snapshot)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            Dictionary<string, string> metadata = new Dictionary<string, string>();
            AddMetadataString(metadata, IdKey, snapshot.Id);
            AddMetadataString(metadata, FullNameKey, snapshot.FullName);
            AddMetadataString(metadata, ShortNameKey, snapshot.ShortName);
            AddMetadataNullableInt32(metadata, HeartbeatExpirationInSecondsKey, snapshot.HeartbeatExpirationInSeconds);
            AddMetadataString(metadata, HeartbeatSharedContainerNameKey, snapshot.HeartbeatSharedContainerName);
            AddMetadataString(metadata, HeartbeatSharedDirectoryNameKey, snapshot.HeartbeatSharedDirectoryName);

            return metadata;
        }
示例#8
0
        public static IDictionary <string, string> CreateOtherMetadata(FunctionSnapshot snapshot)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            Dictionary <string, string> metadata = new Dictionary <string, string>();

            AddMetadataString(metadata, IdKey, snapshot.Id);
            AddMetadataString(metadata, FullNameKey, snapshot.FullName);
            AddMetadataString(metadata, ShortNameKey, snapshot.ShortName);
            AddMetadataNullableInt32(metadata, HeartbeatExpirationInSecondsKey, snapshot.HeartbeatExpirationInSeconds);
            AddMetadataString(metadata, HeartbeatSharedContainerNameKey, snapshot.HeartbeatSharedContainerName);
            AddMetadataString(metadata, HeartbeatSharedDirectoryNameKey, snapshot.HeartbeatSharedDirectoryName);

            return(metadata);
        }
示例#9
0
 public bool CreateOrUpdateIfLatest(FunctionSnapshot snapshot)
 {
     return(_store.CreateOrUpdateIfLatest(snapshot.Id, snapshot.HostVersion, CreateOtherMetadata(snapshot),
                                          snapshot));
 }
 private RunFunctionViewModel CreateRunFunctionViewModel(FunctionSnapshot function, IEnumerable<FunctionParameterViewModel> parameters, string submitText, Guid? parentId)
 {
     return new RunFunctionViewModel
     {
         QueueName = function.QueueName,
         FunctionId = function.Id,
         Parameters = parameters,
         ParentId = parentId,
         FunctionName = function.ShortName,
         FunctionFullName = function.FullName,
         HostIsNotRunning = !FunctionsController.HostHasHeartbeat(_heartbeatMonitor, function).GetValueOrDefault(true),
         SubmitText = submitText
     };
 }
        private ActionResult Invoke(string queueName, FormCollection form, FunctionSnapshot function, ExecutionReason reason, Guid? parentId)
        {
            if (function == null)
            {
                return HttpNotFound();
            }

            IDictionary<string, string> arguments = GetArguments(form);

            Guid id = _invoker.TriggerAndOverride(queueName, function, arguments, parentId, reason);

            return Redirect("~/#/functions/invocations/" + id);
        }
 private static StoreItem CreateStoreItem(FunctionSnapshot snapshot)
 {
     return new StoreItem
     {
         FunctionSnapshot = snapshot,
         ETag = Guid.NewGuid().ToString()
     };
 }
 private static IDictionary<string, string> CreateOtherMetadata(FunctionSnapshot snapshot)
 {
     return FunctionIndexEntry.CreateOtherMetadata(snapshot);
 }
示例#14
0
 public bool UpdateOrCreateIfLatest(FunctionSnapshot snapshot, string currentETag, DateTimeOffset currentVersion)
 {
     return(_store.UpdateOrCreateIfLatest(snapshot.Id, snapshot.HostVersion, CreateOtherMetadata(snapshot),
                                          snapshot, currentETag, currentVersion));
 }
 internal static bool? HostHasHeartbeat(IHeartbeatValidityMonitor heartbeatMonitor, FunctionSnapshot snapshot)
 {
     return HostHasHeartbeat(heartbeatMonitor, snapshot.HeartbeatExpirationInSeconds,
         snapshot.HeartbeatSharedContainerName, snapshot.HeartbeatSharedDirectoryName);
 }
        private static bool TryResolveParameters(FunctionSnapshot function, FunctionInstanceSnapshot snapshot, out IEnumerable<FunctionParameterViewModel> resolvedParameters)
        {
            List<FunctionParameterViewModel> parameters = new List<FunctionParameterViewModel>();

            foreach (KeyValuePair<string, ParameterSnapshot> parameter in function.Parameters)
            {
                if (!snapshot.Arguments.ContainsKey(parameter.Key))
                {
                    resolvedParameters = null;
                    return false;
                }
                
                FunctionParameterViewModel parameterModel = new FunctionParameterViewModel
                {
                    Name = parameter.Key,
                    Description = parameter.Value.Prompt,
                    Value = snapshot.Arguments[parameter.Key].Value
                };
                
                parameters.Add(parameterModel);
            }

            resolvedParameters = parameters;
            return true;
        }
        private static IEnumerable<FunctionParameterViewModel> CreateParameters(FunctionSnapshot function)
        {
            List<FunctionParameterViewModel> parameters = new List<FunctionParameterViewModel>();

            foreach (KeyValuePair<string, ParameterSnapshot> parameter in function.Parameters)
            {
                FunctionParameterViewModel parameterModel = new FunctionParameterViewModel
                {
                    Name = parameter.Key,
                    Description = parameter.Value.Prompt,
                    Value = parameter.Value.DefaultValue
                };
                parameters.Add(parameterModel);
            }

            return parameters;
        }
示例#18
0
 private IDictionary <string, string> CreateOtherMetadata(FunctionSnapshot snapshot)
 {
     return(FunctionIndexEntry.CreateOtherMetadata(snapshot));
 }
示例#19
0
 public Guid TriggerAndOverride(string queueName, FunctionSnapshot function, IDictionary <string, string> arguments, Guid?parentId, ExecutionReason reason)
 {
     throw new NotImplementedException();
 }