Exemplo n.º 1
0
        public void UpdateService(string serviceName, OverlayData[] addInfo, string[] removeAttr)
        {
            // 0. check if the executing node is the owner of the service
            if (!CheckServiceOwner(serviceName)) {
                return;
            }

            // 1. do remove
            if (removeAttr != null && removeAttr.Any()) {
                RemoveService(serviceName, removeAttr);
            }

            // 2. do add
            if (addInfo != null && addInfo.Any()) {
                // add service name for full info
                addInfo = addInfo.Select(d => new OverlayData(d) { ServiceName = serviceName }).ToArray();
                PutService(addInfo, serviceName, PutStorageBehavior.Update);
            }
        }
Exemplo n.º 2
0
        // TODO: handle putBehavior
        public OverlayData[] Put(OverlayData[] od, PutStorageBehavior putBehavior)
        {
            if (!PutServiceFrequencyThreshold.Check() || !CheckAVThreshold()) {
                throw new PutServiceException();
            }

            var data = GetDataCollection();
            if (putBehavior == PutStorageBehavior.Overwrite) {
                data.InsertBatch(
                    od.Select(d => GetInsertOverlayData(d))
                );
            } else if (putBehavior == PutStorageBehavior.Update) {
                foreach (var d in od) {
                    var items = data.Find(
                                    MongoQueryBuilder.And(
                                        MongoQueryBuilder.EQ(ServiceNameFieldName, d.ServiceName),
                                        MongoQueryBuilder.EQ(AttributeFieldName, d.AttrValue.Key)
                                    )
                                );
                    if (items != null && items.Size() > 0) {
                        foreach (var item in items) {
                            item[ValueFieldName] = GetTypedBsonValue(d);
                            item[ValueTypeFieldName] = GetValueTypeFieldValue(d);
                            data.Save(item);
                        }
                    } else {
                        data.Insert(GetInsertOverlayData(d));
                    }
                }
            }
            return od;
        }