private async Task HandleCommand(FileInfo manifestFile)
        {
            if (manifestFile == null)
            {
                throw new ArgumentNullException(nameof(manifestFile));
            }

            string          manifestJson = File.ReadAllText(manifestFile.FullName);
            ServiceManifest manifest     =
                JsonConvert.DeserializeObject <ServiceManifest>(manifestJson, this.serializerSettingsProvider.Instance);

            try
            {
                await this.tenantStore.CreateServiceTenantAsync(manifest).ConfigureAwait(false);
            }
            catch (InvalidServiceManifestException ex)
            {
                Console.WriteLine(ex.Message);

                foreach (string current in ex.Errors)
                {
                    Console.Write("     ");
                    Console.WriteLine(current);
                }
            }
        }
Пример #2
0
        public void ThenTheConfigurationItemWithIndexShouldBeOfType(int index, string expectedTypeName)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>();

            ServiceManifestRequiredConfigurationEntry configurationItem = manifest.RequiredConfigurationEntries[index];

            Assert.AreEqual(expectedTypeName, configurationItem.GetType().Name);
        }
Пример #3
0
        public Task WhenIValidateTheServiceManifestCalled(string manifestName)
        {
            ITenantStore    store    = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <ITenantStore>();
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>(manifestName);

            return(CatchException.AndStoreInScenarioContextAsync(
                       this.scenarioContext,
                       () => manifest.ValidateAndThrowAsync(store)));
        }
Пример #4
0
        public async Task GivenIHaveUsedTheTenantStoreToCreateAServiceTenantWithManifest(string manifestName)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>(manifestName);

            ITenantStore service = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <ITenantStore>();

            ITenant newTenant = await service.CreateServiceTenantAsync(manifest).ConfigureAwait(false);

            this.scenarioContext.Set(newTenant.Id, manifest.ServiceName);
        }
Пример #5
0
 public void WhenIDeserializeTheManifestCalled(string manifestName)
 {
     CatchException.AndStoreInScenarioContext(
         this.scenarioContext,
         () =>
     {
         ServiceManifest manifest = this.LoadManifestFile(manifestName);
         this.scenarioContext.Set(manifest);
     });
 }
Пример #6
0
        public void GivenTheServiceManifestCalledHasTheFollowingAzureTableStorageConfigurationEntries(string manifestName, Table table)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>(manifestName);

            manifest.RequiredConfigurationEntries.Add(new ServiceManifestTableStorageConfigurationEntry
            {
                Key                 = table.Rows[0]["Key"],
                Description         = table.Rows[0]["Description"],
                ContainerDefinition = new TableStorageTableDefinition(table.Rows[0]["Table Name"]),
            });
        }
Пример #7
0
        /// <summary>
        /// Creates repository configuration properties to add the given <see cref="ServiceManifest"/> to the tenant's property bag.
        /// </summary>
        /// <param name="values">Existing configuration values to which to append these.</param>
        /// <param name="manifest">The manifest to add.</param>
        /// <remarks>
        /// This method does not persist the tenant. Calling code should pass the resulting list to
        /// <see cref="ITenantStore.UpdateTenantAsync(string, string?, IEnumerable{KeyValuePair{string, object}}?, IEnumerable{string}?)"/>.
        /// </remarks>
        /// <returns>
        /// Properties to pass to
        /// <see cref="ITenantStore.UpdateTenantAsync(string, string?, IEnumerable{KeyValuePair{string, object}}?, IEnumerable{string}?)"/>.
        /// </returns>
        internal static IEnumerable <KeyValuePair <string, object> > AddServiceManifest(
            this IEnumerable <KeyValuePair <string, object> > values,
            ServiceManifest manifest)
        {
            if (manifest == null)
            {
                throw new ArgumentNullException(nameof(manifest));
            }

            return(values.Append(new KeyValuePair <string, object>(TenantPropertyKeys.ServiceManifest, manifest)));
        }
Пример #8
0
        public Task CreateServiceTenantWithExceptionHandlingAsync(ServiceManifest manifest)
        {
            ITenantStore service = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <ITenantStore>();

            return(CatchException.AndStoreInScenarioContextAsync(
                       this.scenarioContext,
                       async() =>
            {
                ITenant newTenant = await service.CreateServiceTenantAsync(manifest).ConfigureAwait(false);
                this.scenarioContext.Set(newTenant.Id, manifest.ServiceName);
            }));
        }
Пример #9
0
        public void GivenTheServiceManifestCalledHasTheFollowingDependencies(string manifestName, Table dependencyTable)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>(manifestName);

            foreach (TableRow row in dependencyTable.Rows)
            {
                manifest.DependsOnServiceTenants.Add(new ServiceDependency
                {
                    Id           = row[0],
                    ExpectedName = row[1],
                });
            }
        }
Пример #10
0
        public void GivenIHaveAServiceManifestCalled(string manifestName, string serviceName)
        {
            if (serviceName != null)
            {
                serviceName = serviceName.TrimStart('"').TrimEnd('"');
            }

            var manifest = new ServiceManifest
            {
                WellKnownTenantGuid = Guid.NewGuid(),
                ServiceName         = serviceName,
            };

            this.scenarioContext.Set(manifest, manifestName);
        }
        /// <summary>
        /// Retrieves the complete list of configuration items required in order to enroll a tenant to a service. This will
        /// include configuration entries required by any dependent services.
        /// </summary>
        /// <param name="tenantStore">The tenant store.</param>
        /// <param name="serviceTenant">The service to gather configuration for.</param>
        /// <returns>
        /// A list of <see cref="ServiceManifestRequiredConfigurationEntry"/> representing the configuration requirements.
        /// </returns>
        public static async Task <ServiceManifestRequiredConfigurationEntry[]> GetServiceEnrollmentConfigurationRequirementsAsync(this ITenantStore tenantStore, ITenant serviceTenant)
        {
            serviceTenant.EnsureTenantIsOfType(MarainTenantType.Service);

            var             requirements    = new List <ServiceManifestRequiredConfigurationEntry>();
            ServiceManifest serviceManifest = serviceTenant.GetServiceManifest();

            requirements.AddRange(serviceManifest.RequiredConfigurationEntries);

            ServiceManifestRequiredConfigurationEntry[][] dependentServicesConfigRequirements =
                await Task.WhenAll(
                    serviceManifest.DependsOnServiceTenants.Select(
                        x => tenantStore.GetServiceEnrollmentConfigurationRequirementsAsync(x.Id))).ConfigureAwait(false);

            requirements.AddRange(dependentServicesConfigRequirements.SelectMany(x => x));

            return(requirements.ToArray());
        }
        public void SetServicePackagesData(
            ServiceManifest serviceManifest,
            Dictionary <string, GlobalVersion> versions,
            string parentRef)
        {
            var subPackages = versions
                              .Where(x => x.Value.ParentRef.Equals(parentRef))
                              .ToList();

            foreach (var package in subPackages)
            {
                var packageName = package.Key.Split('-')[2];

                switch (package.Value.PackageType)
                {
                case PackageType.Code:
                    serviceManifest.CodePackage.Version = package.Value.Version.ToString();
                    break;

                case PackageType.Config:
                    serviceManifest.ConfigPackage.Version = package.Value.Version.ToString();
                    break;

                case PackageType.Data:
                    var dataPackages = serviceManifest
                                       .DataPackages
                                       .Where(x => x.Name.Equals(packageName, StringComparison.CurrentCultureIgnoreCase))
                                       .ToList();
                    if (!dataPackages.Any())
                    {
                        return;
                    }

                    dataPackages.First().Version = package.Value.Version.ToString();
                    break;

                case PackageType.None:
                    continue;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
        public void ItShouldSetVersionOnServiceManifest()
        {
            // g
            var oldVersion = VersionNumber.Create(1, "hash");
            var newVersion = new GlobalVersion
            {
                Version = VersionNumber.Create(2, "newhash")
            };
            var serviceManifest = new ServiceManifest
            {
                Version = oldVersion.ToString()
            };

            // w
            _serviceManifestHandler.SetServiceManifestGeneral(serviceManifest, newVersion);

            // t
            serviceManifest.Version.Should().Be("2-newhash");
        }
        private void GetPackageTestHelper <TPackage>(
            Action <TPackage, TPackage> comparer,
            PackageFetcher <TPackage> packageFetcher,
            Func <CodePackageActivationContext, string, TPackage> contextPackageFetcher)
            where TPackage : class
        {
            ServiceManifestInfo manifestInfo = ServiceManifestTest.HelperInstance.CreateDefaultInfo();

            var context = new CodePackageActivationContext(new CodePackageActivationContextStub()
            {
                ServiceManifestInfo_Internal = manifestInfo
            });

            ServiceManifest manifestDescription = ServiceManifestTest.HelperInstance.CreateDefaultDescription();

            string pkgName;
            var    pkg = packageFetcher(manifestDescription, out pkgName);
            var    actualPackageFromContext = contextPackageFetcher(context, pkgName);

            comparer(pkg, actualPackageFromContext);
        }
Пример #15
0
        /// <summary>
        /// Get detailed information about a service including information about which databases and other datasources it references, its
        /// source map document path, and other similar information.
        /// </summary>
        /// <param name="service">The name of the service to get information on</param>
        /// <param name="folderName">The name of the containing folder (null or "/" if in the root folder)</param>
        /// <returns>A ServiceManifest object containing detailed information about the service's datasources, names, paths, etc.</returns>
        public async Task <ServiceManifest> GetServiceManifest(ServiceReport service, string folderName = null)
        {
            if (folderName == "/")
            {
                folderName = null;
            }

            Uri serviceManifestEndpoint;

            if (string.IsNullOrEmpty(folderName))
            {
                serviceManifestEndpoint = new Uri(ServerUrl, string.Format("services/{0}.{1}/iteminfo/manifest/manifest.json", service.serviceName, service.type));
            }
            else
            {
                serviceManifestEndpoint = new Uri(ServerUrl, string.Format("services/{0}/{1}.{2}/iteminfo/manifest/manifest.json", folderName, service.serviceName, service.type));
            }

            var parms = new Dictionary <string, string>();

            ServiceManifest response = await GetStringAsync <ServiceManifest>(serviceManifestEndpoint, parms);

            return(response);
        }
Пример #16
0
        public void ThenTheResultingManifestShouldHaveTheServiceName(string serviceName)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>();

            Assert.AreEqual(serviceName, manifest.ServiceName);
        }
        public void ItShouldSetVersionOnPackages()
        {
            // g
            var currentVersion = VersionNumber.Create(1, "hash");
            var newVersion     = VersionNumber.Create(2, "newhash");

            var serviceManifest = new ServiceManifest
            {
                CodePackage = new CodePackage
                {
                    Name    = "Code",
                    Version = currentVersion.ToString()
                },
                ConfigPackage = new ConfigPackage
                {
                    Name    = "Config",
                    Version = currentVersion.ToString()
                },
                DataPackages = new List <DataPackage>
                {
                    new DataPackage
                    {
                        Name    = "MyData",
                        Version = currentVersion.ToString()
                    }
                }
            };

            var parentRef = "Service1";

            var globalVersions = new Dictionary <string, GlobalVersion>
            {
                ["thing-Code"] = new GlobalVersion
                {
                    ParentRef   = parentRef,
                    PackageType = PackageType.Code,
                    VersionType = VersionType.ServicePackage,
                    Version     = newVersion
                },
                ["thing-Config"] = new GlobalVersion
                {
                    ParentRef   = parentRef,
                    PackageType = PackageType.Config,
                    VersionType = VersionType.ServicePackage,
                    Version     = newVersion
                },
                ["thing-MyData"] = new GlobalVersion
                {
                    ParentRef   = parentRef,
                    PackageType = PackageType.Data,
                    VersionType = VersionType.ServicePackage,
                    Version     = newVersion
                }
            };

            // w
            _serviceManifestHandler.SetServicePackagesData(serviceManifest, globalVersions, parentRef);

            // t
            serviceManifest.CodePackage.Version.Should().Be("2-newhash");
            serviceManifest.ConfigPackage.Version.Should().Be("2-newhash");
            serviceManifest.DataPackages.Count.Should().Be(1);
            serviceManifest.DataPackages.First().Version.Should().Be("2-newhash");
        }
 public void SetServiceManifestGeneral(
     ServiceManifest serviceManifest,
     GlobalVersion version)
 {
     serviceManifest.Version = version.Version.ToString();
 }
Пример #19
0
        public void ThenTheResultingManifestShouldHaveAWellKnownServiceGUIDOf(Guid expectedWellKnownServiceGuid)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>();

            Assert.AreEqual(expectedWellKnownServiceGuid, manifest.WellKnownTenantGuid);
        }
Пример #20
0
        public void ThenTheResultingManifestShouldHaveDependencies(int expectedDependencyCount)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>();

            Assert.AreEqual(expectedDependencyCount, manifest.DependsOnServiceTenants.Count);
        }
Пример #21
0
        public void ThenTheResultingManifestShouldNotHaveAnyRequiredConfigurationEntries()
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>();

            Assert.IsEmpty(manifest.RequiredConfigurationEntries);
        }
        /// <summary>
        /// Enrolls the specified tenant in the service.
        /// </summary>
        /// <param name="tenantStore">The tenant store.</param>
        /// <param name="enrollingTenant">The tenant to enroll.</param>
        /// <param name="serviceTenant">The service to enroll in.</param>
        /// <param name="configurationItems">Configuration for the enrollment.</param>
        /// <param name="logger">Optional logger.</param>
        /// <returns>A task which completes when the enrollment has finished.</returns>
        public static async Task EnrollInServiceAsync(
            this ITenantStore tenantStore,
            ITenant enrollingTenant,
            ITenant serviceTenant,
            EnrollmentConfigurationItem[] configurationItems,
            ILogger?logger = null)
        {
            if (enrollingTenant == null)
            {
                throw new ArgumentNullException(nameof(enrollingTenant));
            }

            enrollingTenant.EnsureTenantIsOfType(MarainTenantType.Client, MarainTenantType.Delegated);

            if (serviceTenant == null)
            {
                throw new ArgumentNullException(nameof(serviceTenant));
            }

            serviceTenant.EnsureTenantIsOfType(MarainTenantType.Service);

            if (configurationItems == null)
            {
                throw new ArgumentNullException(nameof(configurationItems));
            }

            logger?.LogDebug(
                "Enrolling tenant '{enrollingTenantName}' with Id '{enrollingTenantId}' from service '{serviceTenantName}' with Id '{serviceTenantId}'",
                enrollingTenant.Name,
                enrollingTenant.Id,
                serviceTenant.Name,
                serviceTenant.Id);

            // First we need to ensure that all the required config items for both the service being enrolled in,
            // as well as any dependent services is provided.
            ServiceManifestRequiredConfigurationEntry[] requiredConfig = await tenantStore.GetServiceEnrollmentConfigurationRequirementsAsync(serviceTenant).ConfigureAwait(false);

            logger?.LogDebug("Validating supplied configuration against required config.");
            configurationItems.ValidateAndThrow(requiredConfig);

            ServiceManifest manifest = serviceTenant.GetServiceManifest();

            // Now, match up the required config items for this service to the relevent supplied config (we may
            // have been supplied with config for dependent services as well, so we can't just attach all
            // of the supplied config items to the enrolling tenant - some of it could belong on delegated
            // tenants.
            logger?.LogDebug(
                "Attaching required configuration items to tenant '{serviceTenantName}' with Id '{serviceTenantId}'",
                serviceTenant.Name,
                serviceTenant.Id);

            IEnumerable <(ServiceManifestRequiredConfigurationEntry RequiredConfigurationEntry, EnrollmentConfigurationItem ProvidedConfigurationItem)> matchedConfigItems =
                manifest.RequiredConfigurationEntries.Select(
                    requiredConfigItem =>
                    (requiredConfigItem, configurationItems.Single(item => item.Key == requiredConfigItem.Key)));

            IEnumerable <KeyValuePair <string, object> > propertiesToAddToEnrollingTenant = PropertyBagValues.Empty;

            foreach ((ServiceManifestRequiredConfigurationEntry RequiredConfigurationEntry, EnrollmentConfigurationItem ProvidedConfigurationItem)current in matchedConfigItems)
            {
                logger?.LogDebug(
                    "Adding configuration entry '{requiredConfigurationEntryKey}' to tenant '{serviceTenantName}' with Id '{serviceTenantId}'",
                    current.RequiredConfigurationEntry.Key,
                    serviceTenant.Name,
                    serviceTenant.Id);

                propertiesToAddToEnrollingTenant = current.RequiredConfigurationEntry.AddToTenantProperties(
                    propertiesToAddToEnrollingTenant, current.ProvidedConfigurationItem);
            }

            // Add an enrollment entry to the tenant.
            logger?.LogDebug(
                "Adding service enrollment to tenant '{serviceTenantName}' with Id '{serviceTenantId}'",
                serviceTenant.Name,
                serviceTenant.Id);

            propertiesToAddToEnrollingTenant = propertiesToAddToEnrollingTenant.AddServiceEnrollment(
                enrollingTenant, serviceTenant.Id);

            // Update the tenant now, so that the tenant type is correctly set - otherwise
            // recursive enrollments will fail
            logger?.LogDebug(
                "Updating tenant '{enrollingTenantName}' with Id '{enrollingTenantId}'",
                enrollingTenant.Name,
                enrollingTenant.Id);

            enrollingTenant = await tenantStore.UpdateTenantAsync(
                enrollingTenant.Id,
                propertiesToSetOrAdd : propertiesToAddToEnrollingTenant)
                              .ConfigureAwait(false);

            propertiesToAddToEnrollingTenant = PropertyBagValues.Empty;

            // If this service has dependencies, we need to create a new delegated tenant for the service to use when
            // accessing those dependencies.
            if (manifest.DependsOnServiceTenants.Count > 0)
            {
                logger?.LogDebug(
                    "Service '{serviceTenantName}' has dependencies. Creating delegated tenant for enrollment.",
                    serviceTenant.Name);

                ITenant delegatedTenant = await tenantStore.CreateDelegatedTenant(enrollingTenant, serviceTenant).ConfigureAwait(false);

                // Now enroll the new delegated tenant for all of the dependent services.
                await Task.WhenAll(manifest.DependsOnServiceTenants.Select(
                                       dependsOnService => tenantStore.EnrollInServiceAsync(
                                           delegatedTenant,
                                           dependsOnService.Id,
                                           configurationItems))).ConfigureAwait(false);

                // Add the delegated tenant Id to the enrolling tenant
                logger?.LogDebug(
                    "Setting delegated tenant for client '{enrollingTenantName}' with Id '{enrollingTenantId}' in service '{serviceTenantName}' with Id '{serviceTenantId}' to new tenant '{delegatedTenantName}' with Id '{delegatedTenantId}'.",
                    enrollingTenant.Name,
                    enrollingTenant.Id,
                    serviceTenant.Name,
                    serviceTenant.Id,
                    delegatedTenant.Name,
                    delegatedTenant.Id);

                propertiesToAddToEnrollingTenant = propertiesToAddToEnrollingTenant.SetDelegatedTenantForService(
                    enrollingTenant, serviceTenant, delegatedTenant);

                logger?.LogDebug(
                    "Updating tenant '{enrollingTenantName}' with Id '{enrollingTenantId}'",
                    enrollingTenant.Name,
                    enrollingTenant.Id);

                await tenantStore.UpdateTenantAsync(
                    enrollingTenant.Id,
                    propertiesToSetOrAdd : propertiesToAddToEnrollingTenant)
                .ConfigureAwait(false);
            }

            logger?.LogInformation(
                "Successfully enrolled tenant '{enrollingTenantName}' with Id '{enrollingTenant.Id}' for service '{serviceTenantName}' with Id '{serviceTenantId}'",
                enrollingTenant.Name,
                enrollingTenant.Id,
                serviceTenant.Name,
                serviceTenant.Id);
        }
        /// <summary>
        /// Unenrolls the specified tenant from the service.
        /// </summary>
        /// <param name="tenantStore">The tenant store.</param>
        /// <param name="enrolledTenant">The tenant that is currently enrolled.</param>
        /// <param name="serviceTenant">The service they need to be unenrolled from.</param>
        /// <param name="logger">Optional logger.</param>
        /// <returns>A task which completes when the unenrollment has finished.</returns>
        public static async Task UnenrollFromServiceAsync(
            this ITenantStore tenantStore,
            ITenant enrolledTenant,
            ITenant serviceTenant,
            ILogger?logger = null)
        {
            if (!enrolledTenant.IsEnrolledForService(serviceTenant.Id))
            {
                throw new InvalidOperationException(
                          $"Cannot unenroll tenant '{enrolledTenant.Name}' with Id '{enrolledTenant.Id}' from service with Id '{serviceTenant.Id}' because it is not currently enrolled");
            }

            logger?.LogDebug(
                "Unenrolling tenant '{enrolledTenantName}' with Id '{enrolledTenantId}' from service '{serviceTenantName}' with Id '{serviceTenantId}'",
                enrolledTenant.Name,
                enrolledTenant.Id,
                serviceTenant.Name,
                serviceTenant.Id);

            var propertiesToRemove = new List <string>();

            ServiceManifest manifest = serviceTenant.GetServiceManifest();

            // If there are dependencies, we first need to unenroll from each of those and then remove the delegated tenant.
            if (manifest.DependsOnServiceTenants.Count > 0)
            {
                logger?.LogDebug(
                    "Service '{serviceTenantName}' has dependencies. Retrieving delegated tenant for unenrollment.",
                    serviceTenant.Name);

                string delegatedTenantId = enrolledTenant.GetDelegatedTenantIdForServiceId(serviceTenant.Id);

                logger?.LogDebug(
                    "Retrieved delegated tenant with Id '{delegatedTenantId}. Unenrolling from dependencies.",
                    delegatedTenantId);

                foreach (ServiceDependency current in manifest.DependsOnServiceTenants)
                {
                    await tenantStore.UnenrollFromServiceAsync(delegatedTenantId, current.Id).ConfigureAwait(false);
                }

                // Now delete the delegated tenant.
                logger?.LogDebug(
                    "Deleting delegated tenant with Id '{delegatedTenantId}'.",
                    delegatedTenantId);
                await tenantStore.DeleteTenantAsync(delegatedTenantId).ConfigureAwait(false);

                propertiesToRemove.AddRange(enrolledTenant.GetPropertiesToRemoveDelegatedTenantForService(serviceTenant));
            }

            if (manifest.RequiredConfigurationEntries.Count > 0)
            {
                // Now remove any config for the service that's being unenrolled from.
                logger?.LogDebug(
                    "Removing configuration for service '{serviceTenantName}' from '{enrolledTenantName}'",
                    serviceTenant.Name,
                    enrolledTenant.Name);

                foreach (ServiceManifestRequiredConfigurationEntry current in manifest.RequiredConfigurationEntries)
                {
                    logger?.LogDebug(
                        "Removing configuration item '{requiredConfigurationEntryKey}' for service '{serviceTenantName}' from '{enrolledTenantName}'",
                        current.Key,
                        serviceTenant.Name,
                        enrolledTenant.Name);
                    propertiesToRemove.AddRange(current.GetPropertiesToRemoveFromTenant(enrolledTenant));
                }
            }

            // Finally, remove the enrollment entry for the service.
            logger?.LogDebug(
                "Removing enrollment entry for service '{serviceTenantName}' from '{enrolledTenantName}'",
                serviceTenant.Name,
                enrolledTenant.Name);

            IEnumerable <KeyValuePair <string, object> > propertiesToChange =
                enrolledTenant.GetPropertyUpdatesToRemoveServiceEnrollment(serviceTenant.Id);

            logger?.LogDebug(
                "Updating tenant '{enrolledTenantName}'",
                enrolledTenant.Name);

            await tenantStore.UpdateTenantAsync(
                enrolledTenant.Id,
                propertiesToSetOrAdd : propertiesToChange,
                propertiesToRemove : propertiesToRemove).ConfigureAwait(false);

            logger?.LogInformation(
                "Successfully unenrolled tenant '{enrolledTenantName}' with Id '{enrolledTenantId}' from service '{serviceTenantName}' with Id '{serviceTenantId}'",
                enrolledTenant.Name,
                enrolledTenant.Id,
                serviceTenant.Name,
                serviceTenant.Id);
        }
Пример #24
0
        public Task WhenIUseTheTenantStoreToCreateANewServiceTenantWithManifest(string manifestName)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>(manifestName);

            return(this.CreateServiceTenantWithExceptionHandlingAsync(manifest));
        }
        /// <summary>
        /// Creates a new tenant representing a Marain service that tenants can enroll to use.
        /// </summary>
        /// <param name="tenantStore">The tenant store.</param>
        /// <param name="manifest">
        /// The manifest for the service. The service name in the manifest must be unique across all service tenants.
        /// </param>
        /// <param name="logger">Optional logger.</param>
        /// <returns>The new tenant.</returns>
        public static async Task <ITenant> CreateServiceTenantAsync(this ITenantStore tenantStore, ServiceManifest manifest, ILogger?logger = null)
        {
            if (manifest == null)
            {
                throw new ArgumentNullException(nameof(manifest));
            }

            logger?.LogDebug("Validating service manifest for service creation.");

            await manifest.ValidateAndThrowAsync(tenantStore).ConfigureAwait(false);

            ITenant parent = await tenantStore.GetServiceTenantParentAsync().ConfigureAwait(false);

            logger?.LogDebug(
                "Creating new service tenant '{serviceName}' with well-known GUID '{wellKnownGuid}'",
                manifest.ServiceName,
                manifest.WellKnownTenantGuid);

            ITenant newTenant = await tenantStore.CreateWellKnownChildTenantAsync(
                parent.Id,
                manifest.WellKnownTenantGuid,
                manifest.ServiceName).ConfigureAwait(false);

            logger?.LogDebug(
                "New service tenant '{serviceName}' created with Id '{tenantId}'; updating tenant type and manifest.",
                newTenant.Name,
                newTenant.Id);

            IEnumerable <KeyValuePair <string, object> > properties = PropertyBagValues.Build(p => p
                                                                                              .AddServiceManifest(manifest)
                                                                                              .AddMarainTenantType(MarainTenantType.Service));

            await tenantStore.UpdateTenantAsync(
                newTenant.Id,
                propertiesToSetOrAdd : properties).ConfigureAwait(false);

            logger?.LogInformation(
                "Created new service tenant '{serviceName}' with Id '{tenantId}'.",
                newTenant.Name,
                newTenant.Id);
            return(newTenant);
        }
Пример #26
0
        public void ThenTheResultingManifestShouldHaveRequiredConfigurationEntry(int expectedConfigurationEntryCount)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>();

            Assert.AreEqual(expectedConfigurationEntryCount, manifest.RequiredConfigurationEntries.Count);
        }
Пример #27
0
        public void ThenTheResultingManifestShouldHaveADependencyWithId(string expectedDependencyId)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>();

            Assert.IsTrue(manifest.DependsOnServiceTenants.Any(x => x.Id == expectedDependencyId));
        }
Пример #28
0
        public void GivenTheWell_KnownTenantGuidForTheManifestCalledIs(string manifestName, Guid wellKnownTenantGuid)
        {
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>(manifestName);

            manifest.WellKnownTenantGuid = wellKnownTenantGuid;
        }
        public void CodePackageActivationContextTest_GetServiceManifestTest()
        {
            ServiceManifestInfo manifest = ServiceManifestTest.HelperInstance.CreateDefaultInfo();

            var context = CodePackageActivationContext.CreateFromNative(new CodePackageActivationContextStub()
            {
                ServiceManifestInfo_Internal = manifest,
                CodePackageName_Internal     = manifest.CodePackages.ElementAt(0).Name
            });

            ServiceManifestTest.HelperInstance.Compare(ServiceManifestTest.HelperInstance.CreateDefaultDescription(), ServiceManifest.CreateFromCodePackageActivationContext(context));
        }
Пример #30
0
        public void GivenIHaveLoadedTheManifestCalled(string manifestName)
        {
            ServiceManifest manifest = this.LoadManifestFile(manifestName);

            this.scenarioContext.Set(manifest, manifestName);
        }