Пример #1
0
        public void Deploy(string deploymentRootPath)
        {
            string serviceManifestFolder = Path.Combine(deploymentRootPath, this.ServiceManifestName);

            FileUtility.CreateDirectoryIfNotExists(serviceManifestFolder);

            LogHelper.Log("Service manifest being created at {0}", serviceManifestFolder);

            ServiceModel.ServiceManifestType serviceManifest = new ServiceModel.ServiceManifestType
            {
                Name        = this.ServiceManifestName,
                Version     = this.Version,
                Description = "Some description"
            };

            this.Services.ForEach((sd) => sd.Generate(serviceManifest, serviceManifestFolder));

            ServiceModel.ApplicationManifestType appManifest = new ServiceModel.ApplicationManifestType
            {
                ApplicationTypeName    = this.Name,
                ApplicationTypeVersion = this.Version,
                Parameters             = this.Parameters.Select
                                         (
                    item => new ServiceModel.ApplicationManifestTypeParameter()
                {
                    Name         = item.Key,
                    DefaultValue = item.Value
                }
                                         ).ToArray()
            };

            appManifest.ServiceTemplates = this.Services
                                           .Select(s => s.GenerateServiceDescription())
                                           .ToArray();

            appManifest.DefaultServices       = new ServiceModel.DefaultServicesType();
            appManifest.DefaultServices.Items = this.Services
                                                .Select(s =>
                                                        new ServiceModel.DefaultServicesTypeService
            {
                Name = string.IsNullOrEmpty(s.ServiceName) ? s.ServiceTypeName : s.ServiceName,
                Item = s.GenerateServiceDescription()
            })
                                                .ToArray();

            var serviceImports = new ServiceModel.ApplicationManifestTypeServiceManifestImport
            {
                ServiceManifestRef = new ServiceModel.ServiceManifestRefType
                {
                    ServiceManifestName    = this.ServiceManifestName,
                    ServiceManifestVersion = this.Version
                }
            };

            appManifest.ServiceManifestImport = new ServiceModel.ApplicationManifestTypeServiceManifestImport[] { serviceImports };

            using (FileStream fs = new FileStream(Path.Combine(serviceManifestFolder, "ServiceManifest.xml"), FileMode.Create))
            {
                XmlWriter xw = ApplicationDeployer.CreateWriter(fs);

                XmlSerializer serializer = new XmlSerializer(typeof(ServiceModel.ServiceManifestType));
                serializer.Serialize(xw, serviceManifest);

                xw.Close();
            }

            using (FileStream fs = new FileStream(Path.Combine(deploymentRootPath, "ApplicationManifest.xml"), FileMode.Create))
            {
                XmlWriter xw = ApplicationDeployer.CreateWriter(fs);

                XmlSerializer serializer = new XmlSerializer(typeof(ServiceModel.ApplicationManifestType));
                serializer.Serialize(xw, appManifest);

                xw.Close();
            }
        }
Пример #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());
        }