예제 #1
0
        private ApplicationManifestTypeServiceManifestImport GetServiceManifestImport(
            ApplicationManifestType applicationManifestType,
            string serviceNamePrefix,
            ComposeServiceTypeDescription serviceTypeDescription,
            out DefaultServicesTypeService defaultServiceEntry,
            out ServiceManifestType serviceManifest)
        {
            IList <PortBindingType> portBindingList;

            serviceManifest = this.CreateServiceManifest(
                serviceNamePrefix,
                applicationManifestType.ApplicationTypeVersion,
                serviceTypeDescription,
                out portBindingList);

            var serviceManifestImport = new ApplicationManifestTypeServiceManifestImport()
            {
                ServiceManifestRef = new ServiceManifestRefType()
                {
                    ServiceManifestName    = serviceManifest.Name,
                    ServiceManifestVersion = serviceManifest.Version
                },
            };

            // Environment variables
            if (serviceTypeDescription.EnvironmentVariables.Count > 0)
            {
                serviceManifestImport.EnvironmentOverrides = new EnvironmentOverridesType[1];

                // one codepackage
                serviceManifestImport.EnvironmentOverrides[0] = this.GetEnvironmentOverrides(serviceTypeDescription,
                                                                                             serviceManifest);
            }

            var servicePackageResourceGovernance = this.GetServicePackageResourceGovernancePolicy(serviceTypeDescription);
            var resourceGovernancePolicies       = this.GetResourceGovernancePolicies(serviceTypeDescription, serviceManifest);

            // Resource governance policy for CP, policy for SP and ContainerHost policy
            serviceManifestImport.Policies = new object[resourceGovernancePolicies.Count + 2];

            int index = 0;

            if (resourceGovernancePolicies.Count != 0)
            {
                resourceGovernancePolicies.ToArray().CopyTo(serviceManifestImport.Policies, index);
                index += resourceGovernancePolicies.Count;
            }

            // Resource governance on SP level
            serviceManifestImport.Policies[index] = servicePackageResourceGovernance;
            ++index;

            // Container Host policies
            serviceManifestImport.Policies[index] = this.GetContainerHostPolicy(serviceTypeDescription, serviceManifest,
                                                                                portBindingList);

            defaultServiceEntry = this.GetDefaultServiceTypeEntry(serviceNamePrefix, serviceTypeDescription);

            return(serviceManifestImport);
        }
예제 #2
0
        private DefaultServicesTypeService GetDefaultServiceTypeEntry(
            string namePrefix,
            ComposeServiceTypeDescription serviceTypeDescription)
        {
            //
            // In order to avoid dns name collisions between services of 2 different applications, service dns names be subdomains
            // under the application name.
            //
            var defaultServiceType = new DefaultServicesTypeService
            {
                Name           = namePrefix,
                ServiceDnsName = this.generateDnsNames ? DockerComposeUtils.GetServiceDnsName(this.applicationName, namePrefix) : "",
                ServicePackageActivationMode = "ExclusiveProcess",
                Item = new StatelessServiceType()
                {
                    InstanceCount      = serviceTypeDescription.InstanceCount.ToString(),
                    ServiceTypeName    = DockerComposeUtils.GetServiceTypeName(namePrefix),
                    SingletonPartition = new ServiceTypeSingletonPartition(),
                },
            };

            if (serviceTypeDescription.PlacementConstraints.Count != 0)
            {
                defaultServiceType.Item.PlacementConstraints =
                    $"({this.MergePlacementConstraints(serviceTypeDescription.PlacementConstraints)})";
            }

            return(defaultServiceType);
        }