Ejemplo n.º 1
0
        public async Task CleanupEndedGamespaces()
        {
            var ts = DateTimeOffset.UtcNow;

            var ended = await _gamespaceStore.List()
                        .Where(g => g.EndTime > DateTimeOffset.MinValue && !g.Cleaned)
                        .ToListAsync()
            ;

            foreach (var gs in ended)
            {
                try
                {
                    _logger.LogInformation($"Cleaning ended gamespace {gs.Id}");

                    await _pod.DeleteAll(gs.Id);

                    gs.Cleaned = true;

                    await _gamespaceStore.Update(gs);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Failed to clean gamespace {gs.Id}");
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <GameState> Stop(string id)
        {
            var ctx = await LoadContext(id);

            await _pod.DeleteAll(id);

            return(await LoadState(ctx.Gamespace));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete a workspace
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Workspace</returns>
        public async Task <Workspace> Delete(int id)
        {
            var entity = await _workspaceStore.Load(id);

            if (entity == null || !entity.CanManage(User))
            {
                throw new InvalidOperationException();
            }

            await _pod.DeleteAll(entity.GlobalId);

            await _workspaceStore.Delete(id);

            return(Mapper.Map <Workspace>(entity, WithActor()));
        }
Ejemplo n.º 4
0
        public async Task <Template> Delete(int id)
        {
            var entity = await _templateStore.Load(id);

            if (entity == null || !entity.Workspace.CanEdit(User))
            {
                throw new InvalidOperationException();
            }

            if (await _templateStore.IsParentTemplate(id))
            {
                throw new ParentTemplateException();
            }

            //delete associated vm
            var deployable = await GetDeployableTemplate(id);

            await _pod.DeleteAll($"{deployable.Name}#{deployable.IsolationTag}");

            //if root template, delete disk(s)
            // TODO: maybe always delete disks?
            if (entity.Parent == null)
            {
                await _pod.DeleteDisks(deployable);
            }

            await _templateStore.Delete(entity.Id);

            return(Mapper.Map <Template>(entity, WithActor()));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Delete a workspace
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Workspace</returns>
        public async Task <Workspace> Delete(string id)
        {
            var entity = await _store.Retrieve(id);

            await _pod.DeleteAll(id);

            await _store.DeleteWithTemplates(id, async templates => {
                var disktasks = Mapper.Map <ConvergedTemplate[]>(templates)
                                .Select(ct => _pod.DeleteDisks(ct.ToVirtualTemplate()))
                                .ToArray()
                ;

                await Task.WhenAll(disktasks);
            });

            return(Mapper.Map <Workspace>(entity));
        }
Ejemplo n.º 6
0
        private async Task RemoveVms(string[] ids)
        {
            var tasks = new List <Task>();

            foreach (var g in ids)
            {
                tasks.Add(_pod.DeleteAll(g));
            }

            await Task.WhenAll(tasks.ToArray());
        }
Ejemplo n.º 7
0
        private async Task <GameState> Destroy(Data.Gamespace gamespace)
        {
            if (gamespace == null || !gamespace.CanEdit(User))
            {
                return(null);
            }

            await _pod.DeleteAll(gamespace.GlobalId);

            await _gamespaceStore.Delete(gamespace.Id);

            return(Mapper.Map <GameState>(gamespace));
        }
Ejemplo n.º 8
0
        private Task RemoveVms(string[] ids)
        {
            var tasks = new List <Task>();

            foreach (var g in ids)
            {
                tasks.Add(_pod.DeleteAll(g));
            }

            Task.WaitAll(tasks.ToArray());

            return(Task.FromResult(0));
        }
Ejemplo n.º 9
0
        public async Task Destroy(string globalId)
        {
            var gamespace = await _gamespaceStore.Load(globalId);

            if (gamespace == null)
            {
                throw new InvalidOperationException();
            }

            await _pod.DeleteAll(gamespace.GlobalId);

            await _gamespaceStore.Delete(gamespace.Id);
        }
Ejemplo n.º 10
0
        public async Task Destroy(string globalId)
        {
            await _pod.DeleteAll(globalId);

            var gamespace = await _gamespaceStore.Load(globalId);

            if (gamespace == null)
            {
                return;
            }

            await _gamespaceStore.Delete(gamespace.Id);
        }
Ejemplo n.º 11
0
        public async Task <GameState> Destroy(int id)
        {
            var gamespace = await _gamespaceStore.Load(id);

            if (gamespace == null || !gamespace.CanEdit(User))
            {
                throw new InvalidOperationException();
            }

            await _pod.DeleteAll(gamespace.GlobalId);

            await _gamespaceStore.Delete(id);

            return(Mapper.Map <GameState>(gamespace));
        }
Ejemplo n.º 12
0
        public async Task <Template> Delete(string id)
        {
            var entity = await _store.Retrieve(id);

            if (await _store.HasDescendents(id))
            {
                throw new TemplateHasDescendents();
            }

            // delete associated vm
            var deployable = await GetDeployableTemplate(id);

            await _pod.DeleteAll($"{deployable.Name}#{deployable.IsolationTag}");

            // if root template, delete disk(s)
            if (entity.IsLinked.Equals(false))
            {
                await _pod.DeleteDisks(deployable);
            }

            await _store.Delete(id);

            return(Mapper.Map <Template>(entity));
        }