示例#1
0
        public Worker(string name,
                      ICoordinator coordinator,
                      WorkerRole role,
                      int maxConcurrentItems,
                      Action<TcpTypedConnection<byte[]>, TcpPackage> onPackageArrived,
                      Func<Guid, VerificationEvent, TcpPackage> packager)
        {
            Ensure.NotNullOrEmpty(name, "name");
            Ensure.NotNull(coordinator, "coordinator");
            Ensure.NotNull(onPackageArrived, "onPackageArrived");
            Ensure.NotNull(packager, "packager");

            _name = name;
            _coordinator = coordinator;
            _role = role;
            _maxConcurrentItems = maxConcurrentItems;
            _onPackageArrived = onPackageArrived;
            _packager = packager;

            _thread = new Thread(MainLoop)
            {
                IsBackground = true,
                Name = string.Format("Worker - {0}", name)
            };
        }
示例#2
0
        static void Main(string[] args)
        {
            var worker = new WorkerRole();

            worker.OnStart();

            worker.Run();

            worker.OnStop();
        }
        /// <summary>
        /// Create a cloud runtime application, essentialy this is a tuple of runtime X package X role
        /// </summary>
        /// <param name="cloudRuntime">The runtime in the tuple</param>
        /// <param name="cloudRuntimePackage">The package in the tuple</param>
        /// <param name="role">The role to apply the package to</param>
        /// <returns>The tuple, use the apply method to apply the runtime as specified</returns>
        public static CloudRuntimeApplicator CreateCloudRuntimeApplicator(CloudRuntime cloudRuntime, CloudRuntimePackage cloudRuntimePackage, WorkerRole role)
        {
            CloudRuntimeApplicator applicator = new CloudRuntimeApplicator
            {
                Runtime = cloudRuntime,
                Package = cloudRuntimePackage,
                WorkerRole = role
            };

            return applicator;
        }
示例#4
0
        internal override void AddRoleToDefinition(ServiceDefinition def, object template)
        {
            base.AddRoleToDefinition(def, template);
            WorkerRole workerRole = template as WorkerRole;
            var toAdd = new WorkerRole[] { workerRole };

            if (def.WorkerRole != null)
            {
                def.WorkerRole = def.WorkerRole.Concat(toAdd).ToArray();
            }
            else
            {
                def.WorkerRole = toAdd;
            }
        }
        private static string GetForwarderName(WebRole[] webRoles, WorkerRole[] workerRoles)
        {
            string forwarderName = null;
            WorkerRole workerForwarder = workerRoles.FirstOrDefault(r => r.Imports != null &&
                r.Imports.Any(i => i.moduleName == "RemoteForwarder"));
            if (workerForwarder != null)
            {
                // a worker role has the forwarder
                forwarderName = workerForwarder.name;
            }
            else
            {
                WebRole webForwarder = webRoles.FirstOrDefault(r => r.Imports != null &&
                    r.Imports.Any(i => i.moduleName == "RemoteForwarder"));
                if (webForwarder != null)
                {
                    // a web role has the forwarder
                    forwarderName = webForwarder.name;
                }
            }

            return forwarderName;
        }
示例#6
0
 public static void WorkerRoleImportsExists(Import expected, WorkerRole actual)
 {
     Assert.IsTrue(Array.Exists<Import>(actual.Imports, i => i.moduleName.Equals(expected.moduleName)));
 }
示例#7
0
 public static void ClearRuntime(WorkerRole role)
 {
      Task startupTask = GetRuntimeStartupTask(role.Startup);
      if (startupTask != null)
      {
          ClearEnvironmentValue(startupTask.Environment, Resources.RuntimeUrlKey);
          ClearEnvironmentValue(startupTask.Environment, Resources.CacheRuntimeUrl);
      }
 }
示例#8
0
        public virtual void ApplyRuntime(CloudRuntimePackage package, WorkerRole workerRole)
        {
            Dictionary<string, string> changes;
            if (this.GetChanges(package, out changes))
            {
                ApplyRoleXmlChanges(changes, workerRole);
            }

            ApplyScaffoldingChanges(package);
        }
示例#9
0
        private static Dictionary<string, string> GetStartupEnvironment(WorkerRole workerRole)
        {
            Dictionary<string, string> settings = new Dictionary<string, string>();
            foreach (Variable variable in GetRuntimeStartupTask(workerRole.Startup).Environment)
            {
                settings[variable.name] = variable.value;
            }

            return settings;
        }
示例#10
0
 private static void ApplyRoleXmlChanges(Dictionary<string, string> changes, WorkerRole workerRole)
 {
     GetRuntimeStartupTask(workerRole.Startup).Environment = ApplySettingChanges(changes, GetRuntimeStartupTask(workerRole.Startup).Environment);
 }
示例#11
0
 private static void Main(string[] args)
 {
     WorkerRole workerRole = new WorkerRole();
     workerRole.Run();
 }
示例#12
0
 public static Collection<CloudRuntime> CreateRuntime(WorkerRole workerRole, string rolePath)
 {
     return GetRuntimes(GetStartupEnvironment(workerRole), workerRole.name, rolePath);
 }
示例#13
0
 protected override void OnStart(string[] args)
 {
     var tasks = new ProviderCollection<WorkerRoleTask>(typeof(WorkerRole));
     workerRole_ = new WorkerRole(tasks);
     workerRole_.OnStart();
 }
 public static void VerifyWorkerRole(WorkerRole role, bool isForwarder)
 {
     Assert.AreEqual(isForwarder ? 1 : 0, role.Imports.Where(i => i.moduleName == "RemoteForwarder").Count());
     Assert.AreEqual(1, role.Imports.Where(i => i.moduleName == "RemoteAccess").Count());
 }
        /// <summary>
        /// Checks if the worker role is configured as caching worker role.
        /// </summary>
        /// <param name="workerRole">The worker role object</param>
        /// <returns>True if its caching worker role, false if not</returns>
        private bool IsCacheWorkerRole(WorkerRole workerRole)
        {
            if (workerRole.Imports != null)
            {
                return Array.Exists<Import>(workerRole.Imports, i => i.moduleName == Resources.CachingModuleName);
            }

            return false;
        }
 private static void AddRemoteAccess(WebRole[] webRoles, WorkerRole[] workerRoles)
 {
     // Add RemoteAccess to all roles
     foreach (WebRole webRole in webRoles.Where(r => r.Imports == null || !r.Imports.Any(i => i.moduleName == "RemoteAccess")))
     {
         webRole.Imports = GeneralUtilities.Append(webRole.Imports, new Import { moduleName = "RemoteAccess" });
     }
     foreach (WorkerRole workerRole in workerRoles.Where(r => r.Imports == null || !r.Imports.Any(i => i.moduleName == "RemoteAccess")))
     {
         workerRole.Imports = GeneralUtilities.Append(workerRole.Imports, new Import { moduleName = "RemoteAccess" });
     }
 }
 private static void RemoveOtherRemoteForwarders(WebRole[] webRoles, WorkerRole[] workerRoles, string forwarderName)
 {
     // Remove RemoteForwarder from all but the chosen role
     foreach (WebRole webRole in webRoles)
     {
         if (webRole.name != forwarderName &&
             webRole.Imports != null &&
             webRole.Imports.Any(i => i.moduleName == "RemoteForwarder"))
         {
             webRole.Imports = webRole.Imports.Where(i => i.moduleName != "RemoteForwarder").ToArray();
         }
     }
     foreach (WorkerRole workerRole in workerRoles)
     {
         if (workerRole.name != forwarderName &&
             workerRole.Imports != null &&
             workerRole.Imports.Any(i => i.moduleName == "RemoteForwarder"))
         {
             workerRole.Imports = workerRole.Imports.Where(i => i.moduleName != "RemoteForwarder").ToArray();
         }
     }
 }
 private static string GetForwarderName(WebRole[] webRoles, WorkerRole[] workerRoles)
 {
     string forwarderName = null;
     WorkerRole workerForwarder = workerRoles.FirstOrDefault(r => r.Imports != null && r.Imports.Any(i => i.moduleName == "RemoteForwarder"));
     if (workerForwarder != null)
     {
         // a worker role has the forwarder
         forwarderName = workerForwarder.name;
     }
     else
     {
         WebRole webForwarder = webRoles.FirstOrDefault(r => r.Imports != null && r.Imports.Any(i => i.moduleName == "RemoteForwarder"));
         if (webForwarder != null)
         {
             // a web role has the forwarder
             forwarderName = webForwarder.name;
         }
         else
         {
             // no role has the forwarder yet
             WorkerRole firstWorkerRole = workerRoles.FirstOrDefault();
             if (firstWorkerRole != null)
             {
                 firstWorkerRole.Imports = GeneralUtilities.Append(firstWorkerRole.Imports, new Import { moduleName = "RemoteForwarder" });
                 forwarderName = firstWorkerRole.name;
             }
             else // no worker role, use a web role
             {
                 WebRole firstWebRole = webRoles.FirstOrDefault();
                 if (firstWebRole != null)
                 {
                     firstWebRole.Imports = GeneralUtilities.Append(firstWebRole.Imports, new Import { moduleName = "RemoteForwarder" });
                     forwarderName = firstWebRole.name;
                 }
                 else
                 {
                     throw new InvalidOperationException(Resources.EnableAzureRemoteDesktop_Enable_NoRoles);
                 }
             }
         }
     }
     return forwarderName;
 }
 public ClientInputServiceHost()
 {
     WorkerRole rol = new WorkerRole();
     ClientInputRecieved += new ClientInputRecievedEventHandler(rol.ServiceHost_ClientInputRecieved);
 }
 /// <summary>
 /// Try to get the specified worker role from the given definiiton
 /// </summary>
 /// <param name="definition">The service definiiton</param>
 /// <param name="roleName">The name of the role</param>
 /// <param name="role">output variable where the worker role is returned</param>
 /// <returns>true if the web role is found in the given definition</returns>
 private static bool TryGetWorkerRole(ServiceDefinition definition, string roleName, out WorkerRole role)
 {
     role = definition.WorkerRole.FirstOrDefault<WorkerRole>(r => string.Equals(r.name, roleName,
         StringComparison.OrdinalIgnoreCase));
     return role != null;
 }
 public JobSubmissionServiceHost()
 {
     WorkerRole role = new WorkerRole();
     JobSubmissionRecieved += new JobSubmissionRecievedEventHandler(role.ServiceHost_JobSubmissionRecieved);
 }