Beispiel #1
0
        public async Task <IActionResult> Create([FromBody] CreateInputModel model,
                                                 [FromServices] ITenantRepository tenantRepository)
        {
            //データの入力チェック
            if (!ModelState.IsValid)
            {
                return(JsonBadRequest("Invalid inputs."));
            }

            //同じ名前のノードは登録できないので、確認する
            Node node = await nodeRepository.GetByNameAsync(model.Name);

            if (node != null)
            {
                return(JsonConflict($"Node {model.Name} already exists: ID = {node.Id}"));
            }

            node = new Node()
            {
                Name               = model.Name,
                Memo               = model.Memo,
                Partition          = model.Partition,
                AccessLevel        = model.AccessLevel == null ? NodeAccessLevel.Disabled : model.AccessLevel.Value,
                TensorBoardEnabled = model.TensorBoardEnabled
            };

            if (node.AccessLevel != NodeAccessLevel.Disabled)
            {
                //アクセスレベルがDisable以外であれば、k8sとの同期を行う
                //ノードが存在しない場合を考慮し、もし失敗しても気にせず更新処理を続ける
                await clusterManagementLogic.UpdatePartitionLabelAsync(node.Name, node.Partition);

                if (node.TensorBoardEnabled)
                {
                    await clusterManagementLogic.UpdateTensorBoardEnabledLabelAsync(node.Name, true);
                }

                if (node.AccessLevel == NodeAccessLevel.Private)
                {
                    //テナントをアサイン
                    if (model.AssignedTenantIds != null)
                    {
                        foreach (long tenantId in model.AssignedTenantIds)
                        {
                            if (tenantRepository.Get(tenantId) == null)
                            {
                                return(JsonNotFound($"Tenant ID {tenantId} is not found."));
                            }
                        }
                        nodeRepository.AssignTenants(node, model.AssignedTenantIds, true);
                    }
                }
            }

            nodeRepository.Add(node);
            unitOfWork.Commit();

            return(JsonCreated(new IndexOutputModel(node)));
        }
        public void PostNode(wnode node)
        {
            Nodes newnode = new Nodes();

            newnode.Node    = node.hostname;
            newnode.Enctext = node.enctext;
            repository.Add(newnode);
        }
Beispiel #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var port    = int.Parse(txtPort.Text.Trim());
            var address = txtAddress.Text.Trim();
            var name    = txtName.Text.Trim();
            var node    = new Node(name, address, port);

            _nodeRepository.Add(node);
            FillList();
            UpdateData();
        }
        private Node InsertNode(Node nodeFirst, int value)
        {
            NodeForCreationDto nodeForCreation = new NodeForCreationDto {
                Value = value
            };
            var node = _mapper.Map <Node>(nodeForCreation);

            if (nodeFirst == null)
            {
                _repo.Add(node);
                return(node);
            }
            InsertNodeRecursive(nodeFirst, node);
            return(node);
        }
Beispiel #5
0
        public async Task <string> AddAsync(Core.Entities.Content.Node node)
        {
            node.Id          = Guid.NewGuid().ToString();
            node.CreatedDate = DateTimeOffset.UtcNow.ToString("s");
            if (node.CustomFields != null)
            {
                node.CustomFields.Id       = Guid.NewGuid().ToString();
                node.CustomFields.EntityId = node.Id;
            }
            _nodeRepository.Add(node);

            var rootId = node.ParentId;

            if (!string.IsNullOrEmpty(node.ParentId))
            {
                var parent = await _nodeRepository.GetAsync(node.ParentId);

                parent.ChildCount += 1;
                _nodeRepository.Update(parent);
                if (!string.IsNullOrEmpty(parent.RootId))
                {
                    rootId = parent.RootId;
                }
            }
            node.RootId = rootId;
            if (!string.IsNullOrEmpty(node.RootId))
            {
                var root = await _nodeRepository.GetAsync(node.RootId);

                root.DescendantCount += 1;
                _nodeRepository.Update(root);
            }

            await _nodeRepository.SaveChangesAsync();

            return(node.Id);
        }
 public async Task Add(Node profile)
 {
     _nodeRepository.Add(profile);
     await _nodeRepository.SaveChangesAsync();
 }
Beispiel #7
0
        public async Task<BlResult<NodeModel>> SaveAsync(NodeModel nodeModel)
        {
            BlResult<NodeModel> blResult = new BlResult<NodeModel>();

            try
            {
                if (nodeModel is null)
                {
                    throw new ArgumentNullException(nameof(NodeModel));
                }

                EnsureTransaction();

                var fetchedEntity = await _nodeRepository.GetByIdAsync(nodeModel.Id);
                fetchedEntity = _mapper.Map(nodeModel, fetchedEntity);
                var attributesToDelete = fetchedEntity.NodeAttributes.
                  Where(x => !nodeModel.NodeAttributes.Any(y => y.Id == x.Id)).ToList();
                var attributesToAdd = nodeModel.NodeAttributes.
                    Where(x => !fetchedEntity.NodeAttributes.Any(y => y.Id == x.Id)).Select(z => z.Id);

                if (nodeModel.Id > 0)
                {
                    _nodeRepository.Edit(fetchedEntity);
                }
                else
                {
                    fetchedEntity = _nodeRepository.Add(fetchedEntity);
                }

                await SaveChangesAsync(false);

                if (attributesToDelete != null && attributesToDelete.Count() > 0)
                {
                    foreach (var item in attributesToDelete)
                    {
                        fetchedEntity.NodeAttributes.Remove(item);
                    }
                    await SaveChangesAsync(false);
                }

                if (attributesToAdd != null && attributesToAdd.Count() > 0)
                {
                    await _nodeRepository.AddAttribuets(fetchedEntity, attributesToAdd);
                    await SaveChangesAsync(false);
                }

                await SaveChangesAsync();

                blResult.Success(_mapper.Map<NodeModel>(fetchedEntity));

            }
            catch (ArgumentNullException)
            {
                blResult.Fail(BLErrorCodeTypeEnum.ArgumentIsNull);
            }
            catch (Exception ex)
            {
                blResult.Fail(BLErrorCodeTypeEnum.Unknown, ex.Message, ex);
            }

            return blResult;
        }
Beispiel #8
0
 public void Add(Node node)
 {
     _session.Add(node);
 }