Beispiel #1
0
        /// <summary>
        /// Processes the dataset request and returns a collection of distribution plans.
        /// </summary>
        /// <param name="activationRequest">
        /// The request that describes the characteristics of the dataset that
        /// should be loaded.
        /// </param>
        /// <param name="token">The cancellation token that can be used to terminate the proposal.</param>
        /// <returns>
        /// The collection containing all the distribution plans.
        /// </returns>
        public IEnumerable <DistributionPlan> ProposeDistributionFor(DatasetActivationRequest activationRequest, CancellationToken token)
        {
            var availableEndpoints = new List <Tuple <EndpointId, IDatasetActivationCommands> >();

            lock (m_Lock)
            {
                foreach (var pair in m_ActivatorCommands)
                {
                    availableEndpoints.Add(new Tuple <EndpointId, IDatasetActivationCommands>(pair.Key, pair.Value));
                }
            }

            using (m_Diagnostics.Profiler.Measure(BaseConstants.TimingGroup, "Generating remote proposal"))
            {
                var proposals = RetrieveProposals(availableEndpoints, m_Configuration, activationRequest, token);
                return(proposals
                       .Select(
                           p =>
                {
                    return new DistributionPlan(
                        ImplementPlan,
                        activationRequest.DatasetToActivate,
                        new NetworkIdentifier(p.Endpoint.OriginatesOnMachine()),
                        p);
                })
                       .ToList());
            }
        }
Beispiel #2
0
        private static IEnumerable <DatasetActivationProposal> RetrieveProposals(
            IEnumerable <Tuple <EndpointId, IDatasetActivationCommands> > availableEndpoints,
            IConfiguration configuration,
            DatasetActivationRequest activationRequest,
            CancellationToken token)
        {
            var usableNodes      = DetermineUsableEndpoints(availableEndpoints, configuration);
            var orderedProposals = OrderProposals(activationRequest.ExpectedLoadPerMachine, activationRequest.PreferredLocations, usableNodes, token);

            return(orderedProposals);
        }
Beispiel #3
0
 /// <summary>
 /// Processes the dataset request and returns a collection of distribution plans.
 /// </summary>
 /// <param name="activationRequest">
 /// The request that describes the characteristics of the dataset that
 /// should be loaded.
 /// </param>
 /// <param name="token">The cancellation token that can be used to terminate the proposal.</param>
 /// <returns>
 /// The collection containing all the distribution plans.
 /// </returns>
 public IEnumerable <DistributionPlan> ProposeDistributionFor(DatasetActivationRequest activationRequest, CancellationToken token)
 {
     using (m_Diagnostics.Profiler.Measure(BaseConstants.TimingGroup, "Generating local proposal"))
     {
         var proposal = m_LocalDistributor.ProposeForLocalMachine(activationRequest.ExpectedLoadPerMachine);
         var plan     = new DistributionPlan(
             ImplementPlan,
             activationRequest.DatasetToActivate,
             new NetworkIdentifier(proposal.Endpoint.OriginatesOnMachine()),
             proposal);
         return(new[] { plan });
     }
 }
        /// <summary>
        /// Processes the dataset request and creates a distribution plan
        /// which can then be accepted by the user.
        /// </summary>
        /// <param name="activationRequest">
        /// The request that describes the characteristics of the dataset that
        /// should be loaded.
        /// </param>
        /// <param name="token">The cancellation token that can be used to terminate the proposal.</param>
        /// <returns>
        /// The distribution plan that takes into account the characteristics of
        /// the dataset and the currently available computing power.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="activationRequest"/> is <see langword="null" />.
        /// </exception>
        public IEnumerable <DistributionPlan> ProposeDistributionFor(DatasetActivationRequest activationRequest, CancellationToken token)
        {
            {
                Enforce.Argument(() => activationRequest);
            }

            foreach (var distributor in m_Distributors)
            {
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }

                var proposals = distributor.ProposeDistributionFor(activationRequest, token);
                foreach (var proposal in proposals)
                {
                    yield return(proposal);
                }
            }
        }
        /// <summary>
        /// Processes the dataset request and creates a distribution plan 
        /// which can then be accepted by the user.
        /// </summary>
        /// <param name="activationRequest">
        /// The request that describes the characteristics of the dataset that 
        /// should be loaded.
        /// </param>
        /// <param name="token">The cancellation token that can be used to terminate the proposal.</param>
        /// <returns>
        /// The distribution plan that takes into account the characteristics of
        /// the dataset and the currently available computing power.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="activationRequest"/> is <see langword="null" />.
        /// </exception>
        public IEnumerable<DistributionPlan> ProposeDistributionFor(DatasetActivationRequest activationRequest, CancellationToken token)
        {
            {
                Enforce.Argument(() => activationRequest);
            }

            foreach (var distributor in m_Distributors)
            {
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }

                var proposals = distributor.ProposeDistributionFor(activationRequest, token);
                foreach (var proposal in proposals)
                {
                    yield return proposal;
                }
            }
        }
        public void ProposeDistributionFor()
        {
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var offlineInfo       = CreateOfflineInfo(new Mock <IPersistenceInformation>().Object);
            var result            = new DatasetActivationProposal
            {
                Endpoint                   = EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                IsAvailable                = true,
                ActivationTime             = new TimeSpan(0, 1, 0),
                TransferTime               = new TimeSpan(0, 1, 0),
                PercentageOfAvailableDisk  = 50,
                PercentageOfMaximumMemory  = 50,
                PercentageOfPhysicalMemory = 50,
            };

            var localDistributor = new Mock <ICalculateDistributionParameters>();
            {
                localDistributor.Setup(l => l.ProposeForLocalMachine(It.IsAny <ExpectedDatasetLoad>()))
                .Returns(result);
            }

            var communicationLayer = new Mock <ICommunicationLayer>();
            {
                communicationLayer.Setup(s => s.LocalConnectionFor(It.Is <ChannelType>(c => c == ChannelType.NamedPipe)))
                .Returns(
                    new Tuple <EndpointId, Uri, Uri>(
                        EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                        new Uri("net.pipe://localhost/pipe"),
                        new Uri("net.pipe://localhost/pipe/data")));
            }

            var loader          = new Mock <IDatasetActivator>();
            var commandHub      = new Mock <ISendCommandsToRemoteEndpoints>();
            var notificationHub = new Mock <INotifyOfRemoteEndpointEvents>();
            var uploads         = new Mock <IStoreUploads>();

            var distributor = new LocalDatasetDistributor(
                localDistributor.Object,
                loader.Object,
                commandHub.Object,
                notificationHub.Object,
                uploads.Object,
                (d, e, n) =>
            {
                return(new DatasetOnlineInformation(
                           d,
                           e,
                           n,
                           commandHub.Object,
                           notificationHub.Object,
                           systemDiagnostics));
            },
                communicationLayer.Object,
                systemDiagnostics,
                new CurrentThreadTaskScheduler());

            var request = new DatasetActivationRequest
            {
                DatasetToActivate      = offlineInfo,
                ExpectedLoadPerMachine = new ExpectedDatasetLoad(),
                PreferredLocations     = DistributionLocations.All,
            };
            var plans = distributor.ProposeDistributionFor(request, new CancellationToken());

            Assert.AreEqual(1, plans.Count());

            var plan = plans.First();

            Assert.IsTrue(ReferenceEquals(offlineInfo, plan.DistributionFor));
            Assert.AreEqual(new NetworkIdentifier(result.Endpoint.OriginatesOnMachine()), plan.MachineToDistributeTo);
            Assert.IsTrue(ReferenceEquals(result, plan.Proposal));
        }
        public void ProposeDistributionFor()
        {
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var offlineInfo = CreateOfflineInfo(new Mock<IPersistenceInformation>().Object);
            var result = new DatasetActivationProposal
            {
                Endpoint = EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                IsAvailable = true,
                ActivationTime = new TimeSpan(0, 1, 0),
                TransferTime = new TimeSpan(0, 1, 0),
                PercentageOfAvailableDisk = 50,
                PercentageOfMaximumMemory = 50,
                PercentageOfPhysicalMemory = 50,
            };

            var loaderCommands = new Mock<IDatasetActivationCommands>();
            {
                loaderCommands.Setup(l => l.ProposeFor(It.IsAny<ExpectedDatasetLoad>()))
                    .Returns(
                        Task.Factory.StartNew(
                            () => result,
                            new CancellationToken(),
                            TaskCreationOptions.None,
                            new CurrentThreadTaskScheduler()))
                    .Verifiable();
            }

            var commandHub = new Mock<ISendCommandsToRemoteEndpoints>();
            {
                commandHub.Setup(h => h.CommandsFor<IDatasetActivationCommands>(It.IsAny<EndpointId>()))
                    .Returns(loaderCommands.Object);
            }

            var notificationHub = new Mock<INotifyOfRemoteEndpointEvents>();

            var offlimitsMachines = new SortedList<string, object>
                {
                    { "someKeyStuff", "otherMachine" }
                };
            var config = new Mock<IConfiguration>();
            {
                config.Setup(c => c.HasValueFor(It.IsAny<ConfigurationKey>()))
                    .Returns(true);
                config.Setup(c => c.Value<IDictionary<string, object>>(It.IsAny<ConfigurationKey>()))
                    .Returns(offlimitsMachines);
            }

            var communicationLayer = new Mock<ICommunicationLayer>();
            {
                communicationLayer.Setup(s => s.LocalConnectionFor(It.Is<ChannelType>(c => c == ChannelType.TcpIP)))
                    .Returns(
                        new Tuple<EndpointId, Uri, Uri>(
                            EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                            new Uri("net.tcp://localhost/tcp"),
                            new Uri("net.tcp://localhost/tcp/data")));
            }

            var distributor = new RemoteDatasetDistributor(
                config.Object,
                commandHub.Object,
                notificationHub.Object,
                new Mock<IStoreUploads>().Object,
                (d, e, n) => new DatasetOnlineInformation(
                    d,
                    e,
                    n,
                    commandHub.Object,
                    notificationHub.Object,
                    systemDiagnostics),
                communicationLayer.Object,
                systemDiagnostics,
                new CurrentThreadTaskScheduler());

            // Add the remote endpoints
            var forbiddenMachineId = new EndpointId("otherMachine:8080");
            commandHub.Raise(
                h => h.OnEndpointSignedIn += null,
                new CommandSetAvailabilityEventArgs(
                    forbiddenMachineId,
                    new[] { typeof(IDatasetActivationCommands) }));

            var legalMachineId = new EndpointId("myMachine:8080");
            commandHub.Raise(
                h => h.OnEndpointSignedIn += null,
                new CommandSetAvailabilityEventArgs(
                    legalMachineId,
                    new[] { typeof(IDatasetActivationCommands) }));

            var request = new DatasetActivationRequest
            {
                DatasetToActivate = offlineInfo,
                ExpectedLoadPerMachine = new ExpectedDatasetLoad(),
                PreferredLocations = DistributionLocations.All,
            };
            var plans = distributor.ProposeDistributionFor(request, new CancellationToken());
            var listPlans = plans.ToList();
            Assert.AreEqual(1, listPlans.Count());

            var plan = listPlans[0];
            Assert.IsTrue(ReferenceEquals(offlineInfo, plan.DistributionFor));
            Assert.AreEqual(new NetworkIdentifier(result.Endpoint.OriginatesOnMachine()), plan.MachineToDistributeTo);
            Assert.IsTrue(ReferenceEquals(result, plan.Proposal));

            loaderCommands.Verify(l => l.ProposeFor(It.IsAny<ExpectedDatasetLoad>()), Times.Once());
        }
 /// <summary>
 /// Processes the dataset request and returns a collection of distribution plans.
 /// </summary>
 /// <param name="activationRequest">
 /// The request that describes the characteristics of the dataset that 
 /// should be loaded.
 /// </param>
 /// <param name="token">The cancellation token that can be used to terminate the proposal.</param>
 /// <returns>
 /// The collection containing all the distribution plans.
 /// </returns>
 public IEnumerable<DistributionPlan> ProposeDistributionFor(DatasetActivationRequest activationRequest, CancellationToken token)
 {
     using (m_Diagnostics.Profiler.Measure(BaseConstants.TimingGroup, "Generating local proposal"))
     {
         var proposal = m_LocalDistributor.ProposeForLocalMachine(activationRequest.ExpectedLoadPerMachine);
         var plan = new DistributionPlan(
             ImplementPlan,
             activationRequest.DatasetToActivate,
             new NetworkIdentifier(proposal.Endpoint.OriginatesOnMachine()),
             proposal);
         return new[] { plan };
     }
 }
        public void ProposeDistributionFor()
        {
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var offlineInfo = CreateOfflineInfo(new Mock<IPersistenceInformation>().Object);
            var result = new DatasetActivationProposal
                {
                    Endpoint = EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                    IsAvailable = true,
                    ActivationTime = new TimeSpan(0, 1, 0),
                    TransferTime = new TimeSpan(0, 1, 0),
                    PercentageOfAvailableDisk = 50,
                    PercentageOfMaximumMemory = 50,
                    PercentageOfPhysicalMemory = 50,
                };

            var localDistributor = new Mock<ICalculateDistributionParameters>();
            {
                localDistributor.Setup(l => l.ProposeForLocalMachine(It.IsAny<ExpectedDatasetLoad>()))
                    .Returns(result);
            }

            var communicationLayer = new Mock<ICommunicationLayer>();
            {
                communicationLayer.Setup(s => s.LocalConnectionFor(It.Is<ChannelType>(c => c == ChannelType.NamedPipe)))
                    .Returns(
                        new Tuple<EndpointId, Uri, Uri>(
                            EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                            new Uri("net.pipe://localhost/pipe"),
                            new Uri("net.pipe://localhost/pipe/data")));
            }

            var loader = new Mock<IDatasetActivator>();
            var commandHub = new Mock<ISendCommandsToRemoteEndpoints>();
            var notificationHub = new Mock<INotifyOfRemoteEndpointEvents>();
            var uploads = new Mock<IStoreUploads>();

            var distributor = new LocalDatasetDistributor(
                localDistributor.Object,
                loader.Object,
                commandHub.Object,
                notificationHub.Object,
                uploads.Object,
                (d, e, n) =>
                {
                    return new DatasetOnlineInformation(
                        d,
                        e,
                        n,
                        commandHub.Object,
                        notificationHub.Object,
                        systemDiagnostics);
                },
                communicationLayer.Object,
                systemDiagnostics,
                new CurrentThreadTaskScheduler());

            var request = new DatasetActivationRequest
                {
                    DatasetToActivate = offlineInfo,
                    ExpectedLoadPerMachine = new ExpectedDatasetLoad(),
                    PreferredLocations = DistributionLocations.All,
                };
            var plans = distributor.ProposeDistributionFor(request, new CancellationToken());
            Assert.AreEqual(1, plans.Count());

            var plan = plans.First();
            Assert.IsTrue(ReferenceEquals(offlineInfo, plan.DistributionFor));
            Assert.AreEqual(new NetworkIdentifier(result.Endpoint.OriginatesOnMachine()), plan.MachineToDistributeTo);
            Assert.IsTrue(ReferenceEquals(result, plan.Proposal));
        }
 private static IEnumerable<DatasetActivationProposal> RetrieveProposals(
     IEnumerable<Tuple<EndpointId, IDatasetActivationCommands>> availableEndpoints,
     IConfiguration configuration,
     DatasetActivationRequest activationRequest,
     CancellationToken token)
 {
     var usableNodes = DetermineUsableEndpoints(availableEndpoints, configuration);
     var orderedProposals = OrderProposals(activationRequest.ExpectedLoadPerMachine, activationRequest.PreferredLocations, usableNodes, token);
     return orderedProposals;
 }
        /// <summary>
        /// Processes the dataset request and returns a collection of distribution plans.
        /// </summary>
        /// <param name="activationRequest">
        /// The request that describes the characteristics of the dataset that 
        /// should be loaded.
        /// </param>
        /// <param name="token">The cancellation token that can be used to terminate the proposal.</param>
        /// <returns>
        /// The collection containing all the distribution plans.
        /// </returns>
        public IEnumerable<DistributionPlan> ProposeDistributionFor(DatasetActivationRequest activationRequest, CancellationToken token)
        {
            var availableEndpoints = new List<Tuple<EndpointId, IDatasetActivationCommands>>();
            lock (m_Lock)
            {
                foreach (var pair in m_ActivatorCommands)
                {
                    availableEndpoints.Add(new Tuple<EndpointId, IDatasetActivationCommands>(pair.Key, pair.Value));
                }
            }

            using (m_Diagnostics.Profiler.Measure(BaseConstants.TimingGroup, "Generating remote proposal"))
            {
                var proposals = RetrieveProposals(availableEndpoints, m_Configuration, activationRequest, token);
                return proposals
                    .Select(
                        p =>
                        {
                            return new DistributionPlan(
                                ImplementPlan,
                                activationRequest.DatasetToActivate,
                                new NetworkIdentifier(p.Endpoint.OriginatesOnMachine()),
                                p);
                        })
                    .ToList();
            }
        }
        public void ProposeDistributionFor()
        {
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var offlineInfo = CreateOfflineInfo(new Mock <IPersistenceInformation>().Object);
            var result      = new DatasetActivationProposal
            {
                Endpoint                   = EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                IsAvailable                = true,
                ActivationTime             = new TimeSpan(0, 1, 0),
                TransferTime               = new TimeSpan(0, 1, 0),
                PercentageOfAvailableDisk  = 50,
                PercentageOfMaximumMemory  = 50,
                PercentageOfPhysicalMemory = 50,
            };

            var loaderCommands = new Mock <IDatasetActivationCommands>();
            {
                loaderCommands.Setup(l => l.ProposeFor(It.IsAny <ExpectedDatasetLoad>()))
                .Returns(
                    Task.Factory.StartNew(
                        () => result,
                        new CancellationToken(),
                        TaskCreationOptions.None,
                        new CurrentThreadTaskScheduler()))
                .Verifiable();
            }

            var commandHub = new Mock <ISendCommandsToRemoteEndpoints>();
            {
                commandHub.Setup(h => h.CommandsFor <IDatasetActivationCommands>(It.IsAny <EndpointId>()))
                .Returns(loaderCommands.Object);
            }

            var notificationHub = new Mock <INotifyOfRemoteEndpointEvents>();

            var offlimitsMachines = new SortedList <string, object>
            {
                { "someKeyStuff", "otherMachine" }
            };
            var config = new Mock <IConfiguration>();
            {
                config.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(true);
                config.Setup(c => c.Value <IDictionary <string, object> >(It.IsAny <ConfigurationKey>()))
                .Returns(offlimitsMachines);
            }

            var communicationLayer = new Mock <ICommunicationLayer>();
            {
                communicationLayer.Setup(s => s.LocalConnectionFor(It.Is <ChannelType>(c => c == ChannelType.TcpIP)))
                .Returns(
                    new Tuple <EndpointId, Uri, Uri>(
                        EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                        new Uri("net.tcp://localhost/tcp"),
                        new Uri("net.tcp://localhost/tcp/data")));
            }

            var distributor = new RemoteDatasetDistributor(
                config.Object,
                commandHub.Object,
                notificationHub.Object,
                new Mock <IStoreUploads>().Object,
                (d, e, n) => new DatasetOnlineInformation(
                    d,
                    e,
                    n,
                    commandHub.Object,
                    notificationHub.Object,
                    systemDiagnostics),
                communicationLayer.Object,
                systemDiagnostics,
                new CurrentThreadTaskScheduler());

            // Add the remote endpoints
            var forbiddenMachineId = new EndpointId("otherMachine:8080");

            commandHub.Raise(
                h => h.OnEndpointSignedIn += null,
                new CommandSetAvailabilityEventArgs(
                    forbiddenMachineId,
                    new[] { typeof(IDatasetActivationCommands) }));

            var legalMachineId = new EndpointId("myMachine:8080");

            commandHub.Raise(
                h => h.OnEndpointSignedIn += null,
                new CommandSetAvailabilityEventArgs(
                    legalMachineId,
                    new[] { typeof(IDatasetActivationCommands) }));

            var request = new DatasetActivationRequest
            {
                DatasetToActivate      = offlineInfo,
                ExpectedLoadPerMachine = new ExpectedDatasetLoad(),
                PreferredLocations     = DistributionLocations.All,
            };
            var plans     = distributor.ProposeDistributionFor(request, new CancellationToken());
            var listPlans = plans.ToList();

            Assert.AreEqual(1, listPlans.Count());

            var plan = listPlans[0];

            Assert.IsTrue(ReferenceEquals(offlineInfo, plan.DistributionFor));
            Assert.AreEqual(new NetworkIdentifier(result.Endpoint.OriginatesOnMachine()), plan.MachineToDistributeTo);
            Assert.IsTrue(ReferenceEquals(result, plan.Proposal));

            loaderCommands.Verify(l => l.ProposeFor(It.IsAny <ExpectedDatasetLoad>()), Times.Once());
        }