Пример #1
0
        protected void Initialize(Logger Log, FqStreamID FQSID,
                                  int num, CallerInfo Ci, LocationInfo Li,
                                  StreamFactory.StreamOp op, StreamFactory.StreamSecurityType type,
                                  CompressionType ctype, int ChunkSizeForUpload, int ThreadPoolSize)
        {
            // Logging related
            logger = Log;
            if (logger != null)
            {
                logger.Log("Start ValueDataStream Init DataStructures");
            }

            // Naming related
            streamid        = FQSID;
            stream          = new MetaDataService.FQStreamID();
            stream.HomeId   = FQSID.HomeId;
            stream.AppId    = FQSID.AppId;
            stream.StreamId = FQSID.StreamId;
            BaseDir         = Path.GetFullPath((null != Ci.workingDir) ? Ci.workingDir : Directory.GetCurrentDirectory());
            targetDir       = BaseDir + "/" + streamid.ToString();
            seq_num         = num;
            targetDir       = targetDir + "/" + seq_num;
            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }

            // Ownership related
            caller        = new MetaDataService.Principal();
            caller.HomeId = streamid.HomeId;
            caller.AppId  = Ci.appName;
            owner         = new MetaDataService.Principal();
            owner.HomeId  = streamid.HomeId;
            owner.AppId   = streamid.AppId;

            // Location
            account             = new MetaDataService.AccountInfo();
            account.accountName = Li.accountName;
            account.accountKey  = Li.accountKey;
            account.location    = "" + Li.st;

            // Index related
            index     = new Dictionary <IKey, List <DataBlockInfo> >();
            t_s       = StreamFactory.NowUtc();
            t_e       = 0;
            IndexHash = null;
            isSealed  = false;

            // Low level
            hasher = new SHA256CryptoServiceProvider();

            // State maint
            streamop              = op;
            streamtype            = type;
            streamcompressiontype = ctype;

            //sync related
            this.StreamChunkSizeForUpload = ChunkSizeForUpload;
            this.StreamThreadPoolSize     = ThreadPoolSize;
        }
Пример #2
0
        public bool deleteStream(FqStreamID streamId, CallerInfo Ci, string mdserveraddress = null)
        {
            Logger log       = new Logger();
            string BaseDir   = Path.GetFullPath((null != Ci.workingDir) ? Ci.workingDir : Directory.GetCurrentDirectory());
            string targetDir = BaseDir + "/" + streamId.ToString();

            // string address = ConfigurationManager.AppSettings.Get("MDServerAddress");
            // string address = "http://homelab-vm.cloudapp.net:23456/MetaDataServer/";

            string address = mdserveraddress;

            MetaDataService.IMetaDataService clnt = null;
            if (address != null)
            {
                BasicHttpBinding binding = new BasicHttpBinding();
                ChannelFactory <MetaDataService.IMetaDataService> factory = new ChannelFactory <MetaDataService.IMetaDataService>(binding, address);
                clnt = factory.CreateChannel();
            }

            Dictionary <int, MetaDataService.AccountInfo> accounts = null;
            string containerName; ISync synchronizerForDelete;

            if (address != null)
            {
                try
                {
                    MetaDataService.FQStreamID stream = new MetaDataService.FQStreamID();
                    stream.HomeId   = streamId.HomeId;
                    stream.AppId    = streamId.AppId;
                    stream.StreamId = streamId.StreamId;
                    accounts        = clnt.GetAllAccounts(stream);

                    if (accounts == null)
                    {
                        // no stream of this name on the metadata server
                        return(false);
                    }

                    // TODO: Authentication for this update call
                    clnt.RemoveAllInfo(stream);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception caught {0}", e);
                    return(false);
                }


                foreach (MetaDataService.AccountInfo account in accounts.Values)
                {
                    Boom(targetDir + "/" + account.num);
                    containerName         = streamId.ToString().Replace('/', '-').ToLower() + "-" + account.num;
                    synchronizerForDelete = CreateSyncForAccount(account, containerName, log);
                    synchronizerForDelete.Delete();
                }

                containerName         = streamId.ToString().Replace('/', '-').ToLower();//account info for meta stream = that of seg 0. strange?
                synchronizerForDelete = CreateSyncForAccount(accounts.ElementAt(0).Value, containerName, log);
                synchronizerForDelete.Delete();
            }
            else
            {
                LocalMetaDataServer localMdServer = new LocalMetaDataServer(targetDir + "/" + MetaStream <StrKey, StrValue> .StreamMDFileName, log);
                localMdServer.LoadMetaDataServer();

                Dictionary <int, AccountInfo> tmp = localMdServer.GetAllAccounts(new FQStreamID(streamId.HomeId, streamId.AppId, streamId.StreamId));

                if (tmp != null)
                {
                    MetaDataService.AccountInfo ai         = null;
                    MetaDataService.AccountInfo segment0Ai = null;
                    foreach (AccountInfo account in tmp.Values)
                    {
                        Boom(targetDir + "/" + account.num);
                        containerName         = streamId.ToString().Replace('/', '-').ToLower() + "-" + account.num;
                        ai                    = new MetaDataService.AccountInfo();
                        ai.accountKey         = account.accountKey;
                        ai.accountName        = account.accountName;
                        ai.location           = account.location;
                        ai.keyVersion         = account.keyVersion;
                        ai.num                = account.num;
                        synchronizerForDelete = CreateSyncForAccount(ai, containerName, log);
                        if (synchronizerForDelete != null)
                        {
                            synchronizerForDelete.Delete();
                        }
                        if (segment0Ai == null)
                        {
                            segment0Ai = ai;
                        }
                    }
                    containerName         = streamId.ToString().Replace('/', '-').ToLower();// TODO account info for meta stream = that of seg 0? something is wrong.
                    synchronizerForDelete = CreateSyncForAccount(segment0Ai, containerName, log);
                    if (synchronizerForDelete != null)
                    {
                        synchronizerForDelete.Delete();
                    }
                }
            }

            Boom(targetDir);
            return(true);
        }