Beispiel #1
0
        protected override void Activate(FabricRuntime runtime, CodePackageActivationContext activationContext)
        {
            this.runtime = runtime;

            var serviceTypes = activationContext.GetServiceTypes();

            string codePackageName = activationContext.CodePackageName;

            // register factories for all service types
            foreach (var item in serviceTypes)
            {
                var typeInformation = DefaultEntryPoint.GetImplementationTypeFromExtension(item.Extensions[DefaultEntryPoint.ServiceImplementationTypeExtensionName]);

                // register only service types for this code package
                if (codePackageName == typeInformation.Item1)
                {
                    Type implementationType = Type.GetType(typeInformation.Item2);

                    if (typeof(IStatelessServiceFactory).IsAssignableFrom(implementationType))
                    {
                        runtime.RegisterStatelessServiceFactory(
                            item.ServiceTypeName,
                            (IStatelessServiceFactory)Activator.CreateInstance(implementationType));
                    }
                    else if (typeof(IStatefulServiceFactory).IsAssignableFrom(implementationType))
                    {
                        runtime.RegisterStatefulServiceFactory(
                            item.ServiceTypeName,
                            (IStatefulServiceFactory)Activator.CreateInstance(implementationType));
                    }
                    else
                    {
                        runtime.RegisterServiceType(item.ServiceTypeName, implementationType);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds all the required elements to the manifest
        /// <param name="deploymentFolder">Must be the folder where the service manifest will be placed</param>
        /// </summary>
        public void Generate(ServiceModel.ServiceManifestType manifest, string deploymentFolder)
        {
            Debug.Assert(!string.IsNullOrEmpty(this.ServiceTypeName));
            Debug.Assert(this.ServiceTypeImplementation != null);
            Debug.Assert(this.CodePackageFiles.Count != 0);
            Debug.Assert(this.CodePackageName != null);

            bool implementsRequiredInterface =
                typeof(IStatelessServiceFactory).IsAssignableFrom(this.ServiceTypeImplementation) ||
                typeof(IStatelessServiceInstance).IsAssignableFrom(this.ServiceTypeImplementation) ||
                typeof(IStatefulServiceFactory).IsAssignableFrom(this.ServiceTypeImplementation) ||
                typeof(IStatefulServiceReplica).IsAssignableFrom(this.ServiceTypeImplementation);

            Debug.Assert(implementsRequiredInterface);

            if (this.ConfigurationSettings.Count != 0 && this.ConfigPackageName == null)
            {
                throw new ArgumentException("Configuration settings provided without a config package name");
            }

            if ((this.ConfigPackageFiles.Count != 0 && this.ConfigPackageName == null) || (this.DataPackageFiles.Count != 0 && this.DataPackageName == null))
            {
                throw new ArgumentException("Config/Data package had files but no package name");
            }

            ServiceModel.ServiceTypeType serviceTypeDescription = null;
            if (this.IsStateless)
            {
                serviceTypeDescription = new ServiceModel.StatelessServiceTypeType
                {
                    ServiceTypeName      = this.ServiceTypeName,
                    LoadMetrics          = GenerateStatelessLoadMetrics(),
                    PlacementConstraints = this.PlacementConstraints
                };
            }
            else
            {
                serviceTypeDescription = new ServiceModel.StatefulServiceTypeType
                {
                    ServiceTypeName      = this.ServiceTypeName,
                    HasPersistedState    = this.HasPersistedState,
                    LoadMetrics          = GenerateStatefulLoadMetrics(),
                    PlacementConstraints = this.PlacementConstraints
                };
            }

            XmlDocument dummyDocument = new XmlDocument()
            {
                XmlResolver = null
            };
            var extensionValue = dummyDocument.CreateElement("DefaultEntryPoint", "http://schemas.microsoft.com/2011/01/fabric/servicetypeextension");

            extensionValue.InnerText = DefaultEntryPoint.CreateExtensionValueFromTypeInformation(this.CodePackageName, this.ServiceTypeImplementation);

            serviceTypeDescription.Extensions = new ServiceModel.ExtensionsTypeExtension[]
            {
                new ServiceModel.ExtensionsTypeExtension
                {
                    Name = DefaultEntryPoint.ServiceImplementationTypeExtensionName,
                    Any  = extensionValue
                }
            };

            manifest.ServiceTypes = ServiceDeployer.CreateOrAppend <object>(manifest.ServiceTypes, (object)serviceTypeDescription);

            if (this.ServiceGroupTypeName != null)
            {
                ServiceModel.ServiceGroupTypeType serviceGroupTypeDescription = null;
                if (this.IsStateless)
                {
                    serviceGroupTypeDescription = new ServiceModel.StatelessServiceGroupTypeType
                    {
                        ServiceGroupTypeName = this.ServiceGroupTypeName,
                        ServiceGroupMembers  = new ServiceGroupTypeMember[2] {
                            new ServiceGroupTypeMember {
                                ServiceTypeName = this.ServiceTypeName
                            },
                            new ServiceGroupTypeMember {
                                ServiceTypeName = this.ServiceTypeName
                            }
                        }
                    };
                }
                else
                {
                    serviceGroupTypeDescription = new ServiceModel.StatefulServiceGroupTypeType
                    {
                        ServiceGroupTypeName = this.ServiceGroupTypeName,
                        ServiceGroupMembers  = new ServiceGroupTypeMember[2] {
                            new ServiceGroupTypeMember {
                                ServiceTypeName = this.ServiceTypeName
                            },
                            new ServiceGroupTypeMember {
                                ServiceTypeName = this.ServiceTypeName
                            }
                        }
                    };
                }

                manifest.ServiceTypes = ServiceDeployer.CreateOrAppend <object>(manifest.ServiceTypes, (object)serviceGroupTypeDescription);
            }

            // deploy the packages

            // code package
            // add "system.fabric.test.dll" as a required file
            // add "system.fabric.test.host.dll" as a required file
            this.CodePackageFiles.Add(typeof(ApplicationDeployer).Assembly.Location);

            this.CodePackageFiles.Add(GetFileInAssemblyLocation("System.Fabric.Test.Host.exe"));
            this.DeployPackage(deploymentFolder, this.CodePackageName, this.CodePackageFiles);
            manifest.CodePackage = ServiceDeployer.CreateOrAppend(manifest.CodePackage, this.GenerateCodePackageDescription());

            // config package
            if (this.ConfigPackageName != null)
            {
                this.DeployPackage(deploymentFolder, this.ConfigPackageName, this.ConfigPackageFiles);
                manifest.ConfigPackage = ServiceDeployer.CreateOrAppend(manifest.ConfigPackage, this.GenerateConfigPackageDescription());

                this.WriteConfigurationPackage(deploymentFolder);
            }

            // data package
            if (this.DataPackageName != null)
            {
                this.DeployPackage(deploymentFolder, this.DataPackageName, this.DataPackageFiles);
                manifest.DataPackage = ServiceDeployer.CreateOrAppend(manifest.DataPackage, this.GenerateDataPackageDescription());
            }

            manifest.Resources           = manifest.Resources ?? new ServiceModel.ResourcesType();
            manifest.Resources.Endpoints = ServiceDeployer.CreateOrAppend(manifest.Resources.Endpoints, this.GenerateEndpoints());
        }