Example #1
0
        private ZkprProtocolMessages.Multi DeserializeMulti(int xid)
        {
            // A Multi consists of a repeating pattern of MultiHeader
            // int OpType. (-1 or 0 is no-op)
            // byte if '1' if done or '0'
            // int error byte (set t0 -1 on request)
            // Seralized Op depending on Type
            bool done = false;
            List <IZooKeeperRequest> ops = new List <IZooKeeperRequest>();

            do
            {
                ZkprProtocolMessages.MultiHeader mh = this.DeserializeMultiHeader();
                if (mh.Done)
                {
                    done = true;
                }
                else
                {
                    switch (mh.OpType)
                    {
                    case ZooKeeperRequestType.Create:
                        ZkprProtocolMessages.Create cr = this.DeserializeCreate(xid);
                        ops.Add(cr);
                        break;

                    case ZooKeeperRequestType.Delete:
                        ZkprProtocolMessages.Delete dl = this.DeserializeDelete(xid);
                        ops.Add(dl);
                        break;

                    case ZooKeeperRequestType.SetData:
                        ZkprProtocolMessages.SetData sd = this.DeserializeSetData(xid);
                        ops.Add(sd);
                        break;

                    case ZooKeeperRequestType.Check:
                        ZkprProtocolMessages.Check ch = this.DeserializeCheck(xid);
                        ops.Add(ch);
                        break;
                    }
                }
            }while (!done);

            return(ZkprProtocolMessages.Multi.CreateMulti(xid, ops));
        }
Example #2
0
        private IReadOnlyList <Op> TranslateZkprOpsListToRmOpsList(IReadOnlyList <IZooKeeperRequest> zkprOps)
        {
            List <Op> rmOps = new List <Op>();

            foreach (IZooKeeperRequest zkReq in zkprOps)
            {
                switch (zkReq.RequestType)
                {
                case ZooKeeperRequestType.Create:
                    ZkprProtocolMessages.Create zkCreate = zkReq as ZkprProtocolMessages.Create;
                    IReadOnlyList <Acl>         acls     = this.TranslateZkprAclListToRMAclList(zkCreate.Acls);
                    CreateMode cm = this.TranslateZkprCreatFlagsToRmCreateMode(zkCreate.Flags);

                    rmOps.Add(Op.Create(zkCreate.Path, zkCreate.Data, acls, cm));
                    break;

                case ZooKeeperRequestType.Delete:
                    ZkprProtocolMessages.Delete zkDelete = zkReq as ZkprProtocolMessages.Delete;

                    rmOps.Add(Op.Delete(zkDelete.Path, zkDelete.Version, false));
                    break;

                case ZooKeeperRequestType.SetData:
                    ZkprProtocolMessages.SetData zkSetData = zkReq as ZkprProtocolMessages.SetData;

                    rmOps.Add(Op.SetData(zkSetData.Path, zkSetData.Data, zkSetData.Version));
                    break;

                case ZooKeeperRequestType.Check:
                    ZkprProtocolMessages.Check zkCheck = zkReq as ZkprProtocolMessages.Check;

                    rmOps.Add(Op.Check(zkCheck.Path, zkCheck.Version));
                    break;
                }
            }

            return(rmOps);
        }
Example #3
0
        /// <summary>
        /// Deserialize <see cref="IZooKeeperRequest"/>
        /// </summary>
        /// <param name="xid">the callid</param>
        /// <param name="type">type of the call</param>
        /// <param name="sessionState">The PerSession State</param>
        /// <param name="ringMasterRequest">The ring master request.</param>
        /// <exception cref="System.ArgumentException">unknown type  + type</exception>
        /// <returns>The Zookeeper Request</returns>
        private IZooKeeperRequest DeserializeZooKeeperRequest(int xid, ZooKeeperRequestType type, ZkprPerSessionState sessionState, out IRingMasterRequest ringMasterRequest)
        {
            ringMasterRequest = null;
            switch (type)
            {
            case ZooKeeperRequestType.Notification:     // "0" for Createing a session
                ringMasterRequest = null;
                return(this.DeserializeNotification(xid));

            case ZooKeeperRequestType.CreateSession:
                ZkprProtocolMessages.CreateSession cs = this.DeserializeCreateSession();
                ringMasterRequest            = new RequestInit((ulong)cs.SessionId, cs.IsNullPassword ? string.Empty : cs.Password);
                sessionState.ConnectRecieved = true;
                return(cs);

            case ZooKeeperRequestType.Exists:
                ZkprProtocolMessages.Exists ex = this.DeserializeExists(xid);
                ringMasterRequest = new RequestExists(ex.Path, ex.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse));
                return(ex);

            case ZooKeeperRequestType.GetChildren:
                ZkprProtocolMessages.GetChildren gc = this.DeserializeGetChildren(xid);
                ringMasterRequest = new RequestGetChildren(gc.Path, gc.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse), null);
                return(gc);

            case ZooKeeperRequestType.GetChildren2:
                ZkprProtocolMessages.GetChildren2 gc2 = this.DeserializeGetChildren2(xid);
                ringMasterRequest = new RequestGetChildren(gc2.Path, gc2.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse), null);
                return(gc2);

            case ZooKeeperRequestType.GetData:
                ZkprProtocolMessages.GetData gd = this.DeserializeGetData(xid);
                ringMasterRequest = new RequestGetData(gd.Path, RequestGetData.GetDataOptions.None, gd.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse));
                return(gd);

            case ZooKeeperRequestType.Create:
                ZkprProtocolMessages.Create cr   = this.DeserializeCreate(xid);
                IReadOnlyList <Acl>         acls = this.TranslateZkprAclListToRMAclList(cr.Acls);
                CreateMode cm = this.TranslateZkprCreatFlagsToRmCreateMode(cr.Flags);
                ringMasterRequest = new RequestCreate(cr.Path, cr.Data, acls, cm);
                return(cr);

            case ZooKeeperRequestType.Create2:
                ZkprProtocolMessages.Create2 cr2   = this.DeserializeCreate2(xid);
                IReadOnlyList <Acl>          acls2 = this.TranslateZkprAclListToRMAclList(cr2.Acls);
                CreateMode cm2 = this.TranslateZkprCreatFlagsToRmCreateMode(cr2.Flags);
                ringMasterRequest = new RequestCreate(cr2.Path, cr2.Data, acls2, cm2);
                return(cr2);

            case ZooKeeperRequestType.SetData:
                ZkprProtocolMessages.SetData sd = this.DeserializeSetData(xid);
                ringMasterRequest = new RequestSetData(sd.Path, sd.Data, sd.Version);
                return(sd);

            case ZooKeeperRequestType.Delete:
                ZkprProtocolMessages.Delete dl = this.DeserializeDelete(xid);
                ringMasterRequest = new RequestDelete(dl.Path, dl.Version, false);
                return(dl);

            case ZooKeeperRequestType.Ping:
                ringMasterRequest = null;
                return(this.DeserializePing(xid));

            case ZooKeeperRequestType.CloseSession:
                ringMasterRequest            = null;
                sessionState.ConnectRecieved = false;     // Renegotiate the CreateSession
                return(this.DeserializeCloseSession(xid));

            case ZooKeeperRequestType.GetACL:
                ZkprProtocolMessages.GetACL ga = this.DeserializeGetACL(xid);
                ringMasterRequest = new RequestGetAcl(ga.Path, null);
                return(ga);

            case ZooKeeperRequestType.SetACL:
                ZkprProtocolMessages.SetACL sa      = this.DeserializeSetACL(xid);
                IReadOnlyList <Acl>         sa_acls = this.TranslateZkprAclListToRMAclList(sa.Acls);
                ringMasterRequest = new RequestSetAcl(sa.Path, sa_acls, sa.Version);
                return(sa);

            case ZooKeeperRequestType.Multi:
                ZkprProtocolMessages.Multi mu    = this.DeserializeMulti(xid);
                IReadOnlyList <Op>         rmOps = this.TranslateZkprOpsListToRmOpsList(mu.Ops);
                ringMasterRequest = new RequestMulti(rmOps, false);
                return(mu);

            case ZooKeeperRequestType.Auth:
                ZkprProtocolMessages.Auth au = this.DeserializeAuth(xid);
                ringMasterRequest = new RequestSetAuth(au.RmAuthId);
                return(au);

            case ZooKeeperRequestType.Check:
            case ZooKeeperRequestType.Sync:
            case ZooKeeperRequestType.Reconfig:
            case ZooKeeperRequestType.SetWatches:
            case ZooKeeperRequestType.RemoveWatches:
            case ZooKeeperRequestType.CreateContainer:
            case ZooKeeperRequestType.DeleteContainer:
            case ZooKeeperRequestType.Sasl:
            case ZooKeeperRequestType.Error:
            default:
                break;
            }

            return(null);
        }