public PSEventHubsSchemaRegistryAttributes(SchemaGroup schemaGroup)
        {
            if (schemaGroup != null)
            {
                SchemaCompatibility = schemaGroup.SchemaCompatibility;
                SchemaType          = schemaGroup.SchemaType;

                if (schemaGroup.GroupProperties != null)
                {
                    var groupPropertiesDictionary = new Dictionary <string, string>(schemaGroup.GroupProperties);
                    GroupProperties = new Hashtable(groupPropertiesDictionary);
                }


                if (schemaGroup.Id != null)
                {
                    Id = schemaGroup.Id;
                }

                if (schemaGroup.Name != null)
                {
                    Name = schemaGroup.Name;
                }

                if (schemaGroup.Location != null)
                {
                    Location = schemaGroup.Location;
                }

                if (schemaGroup.Type != null)
                {
                    Type = schemaGroup.Type;
                }
            }
        }
Exemplo n.º 2
0
        public async Task CreateDeleteSchemaGroup()
        {
            //create schema group
            string          schemaGroupName = Recording.GenerateAssetName("schemagroup");
            SchemaGroupData parameters      = new SchemaGroupData()
            {
                SchemaType = SchemaType.Avro
            };
            SchemaGroup schemaGroup = (await _schemaGroupCollection.CreateOrUpdateAsync(true, schemaGroupName, parameters)).Value;

            Assert.NotNull(schemaGroup);
            Assert.AreEqual(schemaGroupName, schemaGroup.Id.Name);

            //validate if created successfully
            schemaGroup = await _schemaGroupCollection.GetIfExistsAsync(schemaGroupName);

            Assert.NotNull(schemaGroup);
            Assert.IsTrue(await _schemaGroupCollection.ExistsAsync(schemaGroupName));

            //delete eventhub
            await schemaGroup.DeleteAsync(true);

            //validate
            schemaGroup = await _schemaGroupCollection.GetIfExistsAsync(schemaGroupName);

            Assert.Null(schemaGroup);
            Assert.IsFalse(await _schemaGroupCollection.ExistsAsync(schemaGroupName));
        }
Exemplo n.º 3
0
        public void Name_ShouldReturnSchemaGroupName()
        {
            var name        = this.fixture.Create <string>();
            var schemaGroup = new SchemaGroup <FileDescriptorSet>(name);

            Assert.Equal(name, schemaGroup.Name);
        }
        public async Task <IActionResult> CreateGroup([FromBody] SchemaGroup body, [FromRoute][Required] string groupId)
        {
            if (_context.SchemaGroups.Where(x => x.Id == groupId).Select(x => true).FirstOrDefault())
            {
                return(StatusCode(409));
            }
            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }

            if (body.Id != groupId)
            {
                return(Problem("Group Id in payload must match route"));
            }

            if (_validators.All(x => x.SchemaFormat != body.Format))
            {
                return(Problem(
                           $"{body.Format} schema is not supported. Valid schemas are {string.Join(",", _validators.Select(v => v.SchemaFormat))}"));
            }

            await _context.SchemaGroups.AddAsync(body);

            await _context.SaveChangesAsync();

            return(Created(Url.Action("GetGroup", new { groupId }), body));
        }
Exemplo n.º 5
0
        public PSEventHubsSchemaRegistryAttributes BeginCreateNamespaceSchemaGroup(string resourceGroupName, string namespaceName, string schemaGroupName
                                                                                   , string schemaCompatibility, string schemaType, Hashtable groupProperties)
        {
            SchemaGroup schemaGroup = new SchemaGroup(schemaCompatibility: schemaCompatibility, schemaType: schemaType);

            if (groupProperties != null)
            {
                schemaGroup.GroupProperties = TagsConversionHelper.CreateTagDictionary(groupProperties, validate: true);;
            }
            var response = Client.SchemaRegistry.CreateOrUpdate(resourceGroupName: resourceGroupName, namespaceName: namespaceName, schemaGroupName: schemaGroupName, parameters: schemaGroup);

            return(new PSEventHubsSchemaRegistryAttributes(response));
        }
Exemplo n.º 6
0
        public void AddSchema_TransitivelyForwardIncompatibleWithOlderSchemas_ShouldReturnRuleViolations()
        {
            this.ruleMock
            .Setup(rule => rule.Validate(It.Is <ProtoBufSchema>(schema => schema.Version == Version.Initial.Next()), It.IsAny <ProtoBufSchema>()))
            .Returns(new ValidationResult(true, this.fixture.Create <string>()));

            this.ruleMock
            .Setup(rule => rule.Validate(It.Is <ProtoBufSchema>(schema => schema.Version == Version.Initial), It.IsAny <ProtoBufSchema>()))
            .Returns(new ValidationResult(false, this.fixture.Create <string>()));

            this.schemaFactoryMock
            .Setup(factory => factory.CreateNew(It.IsAny <Version>(), It.IsAny <string>()))
            .Returns(new ProtoBufSchema(Guid.NewGuid(), Version.Initial.Next().Next(), string.Empty));

            var groupId        = this.fixture.Create <Guid>();
            var firstSchema    = new ProtoBufSchema(Guid.NewGuid(), Version.Initial, string.Empty);
            var previousSchema = new ProtoBufSchema(Guid.NewGuid(), Version.Initial.Next(), string.Empty);
            var schemaGroup    = new SchemaGroup <FileDescriptorSet>(
                groupId,
                this.fixture.Create <string>(),
                new List <Schema <FileDescriptorSet> > {
                firstSchema, previousSchema
            },
                new List <Rule <FileDescriptorSet> > {
                this.ruleMock.Object
            });

            var config = new ConfigurationSet(
                this.fixture.Create <Guid>(),
                new Dictionary <RuleCode, RuleConfig>
            {
                { RuleCode.R0001, new RuleConfig(false, Severity.Error) },
            },
                groupId,
                false,
                true,
                false,
                true);

            IEnumerable <RuleViolation> ruleViolations = schemaGroup.AddSchema(
                this.fixture.Create <string>(),
                config,
                this.schemaFactoryMock.Object);

            Assert.NotEmpty(ruleViolations);
        }
Exemplo n.º 7
0
        public void AddSchema_WithBackwardIncompatibleContentsAndDisabledBackwardCompatibility_ShouldAddSchema()
        {
            this.ruleMock
            .Setup(rule => rule.Validate(It.IsAny <ProtoBufSchema>(), It.Is <ProtoBufSchema>(schema => schema.Version == Version.Initial)))
            .Returns(new ValidationResult(false, this.fixture.Create <string>()));

            this.ruleMock
            .Setup(rule => rule.Validate(It.Is <ProtoBufSchema>(schema => schema.Version == Version.Initial), It.IsAny <ProtoBufSchema>()))
            .Returns(new ValidationResult(true, this.fixture.Create <string>()));

            this.schemaFactoryMock
            .Setup(factory => factory.CreateNew(It.IsAny <Version>(), It.IsAny <string>()))
            .Returns(new ProtoBufSchema(Guid.NewGuid(), Version.Initial.Next().Next(), string.Empty));

            var groupId     = this.fixture.Create <Guid>();
            var firstSchema = new ProtoBufSchema(Guid.NewGuid(), Version.Initial, string.Empty);
            var schemaGroup = new SchemaGroup <FileDescriptorSet>(
                groupId,
                this.fixture.Create <string>(),
                new List <Schema <FileDescriptorSet> > {
                firstSchema
            },
                new List <Rule <FileDescriptorSet> > {
                this.ruleMock.Object
            });

            var config = new ConfigurationSet(
                this.fixture.Create <Guid>(),
                new Dictionary <RuleCode, RuleConfig>
            {
                { RuleCode.R0001, new RuleConfig(false, Severity.Error) },
            },
                groupId,
                false,
                true,
                false,
                false);

            schemaGroup.AddSchema(
                this.fixture.Create <string>(),
                config,
                this.schemaFactoryMock.Object);

            Assert.Equal(2, schemaGroup.Schemas.Count);
        }
Exemplo n.º 8
0
        public void AddSchema_ToGroupWithoutSchemas_ShouldAddSchemaWithInitialVersion()
        {
            var schemaGroup = new SchemaGroup <FileDescriptorSet>(this.fixture.Create <string>());
            var contents    = this.fixture.Create <string>();
            var config      = new ConfigurationSet(
                Guid.NewGuid(),
                new Dictionary <RuleCode, RuleConfig>(),
                schemaGroup.Id,
                true,
                true,
                true,
                true);

            schemaGroup.AddSchema(
                contents,
                config,
                this.schemaFactoryMock.Object);

            this.schemaFactoryMock.Verify(
                factory => factory.CreateNew(Version.Initial, contents),
                "New schema should have initial version when the schema group doesn't have any schemas");
        }
Exemplo n.º 9
0
        public async Task GetAllSchemaGroups()
        {
            //create a schema group
            string          schemaGroupName1 = Recording.GenerateAssetName("schemagroup1");
            SchemaGroupData parameters       = new SchemaGroupData()
            {
                SchemaType = SchemaType.Avro
            };

            _ = (await _schemaGroupCollection.CreateOrUpdateAsync(true, schemaGroupName1, parameters)).Value;

            //validate
            int         count        = 0;
            SchemaGroup schemaGroup1 = null;

            await foreach (SchemaGroup schemaGroup in _schemaGroupCollection.GetAllAsync())
            {
                count++;
                if (schemaGroup.Id.Name == schemaGroupName1)
                {
                    schemaGroup1 = schemaGroup;
                }
            }
        }
Exemplo n.º 10
0
        public PSEventHubsSchemaRegistryAttributes BeginUpdateNamespaceSchemaGroup(string resourceGroupName, string namespaceName, string schemaGroupName
                                                                                   , string schemaCompatibility, string schemaType, IDictionary <string, string> groupProperties)
        {
            SchemaGroup parameters = Client.SchemaRegistry.Get(resourceGroupName: resourceGroupName, namespaceName: namespaceName, schemaGroupName: schemaGroupName);

            if (groupProperties != null)
            {
                parameters.GroupProperties = groupProperties;
            }

            if (schemaCompatibility != null)
            {
                parameters.SchemaCompatibility = schemaCompatibility;
            }

            if (schemaType != null)
            {
                parameters.SchemaType = schemaType;
            }

            var response = Client.SchemaRegistry.CreateOrUpdate(resourceGroupName: resourceGroupName, namespaceName: namespaceName, schemaGroupName: schemaGroupName, parameters: parameters);

            return(new PSEventHubsSchemaRegistryAttributes(response));
        }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of the resource group within the azure subscription.
 /// </param>
 /// <param name='namespaceName'>
 /// The Namespace name
 /// </param>
 /// <param name='schemaGroupName'>
 /// The Schema Group name
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to create an Event Hub resource.
 /// </param>
 public static SchemaGroup CreateOrUpdate(this ISchemaRegistryOperations operations, string resourceGroupName, string namespaceName, string schemaGroupName, SchemaGroup parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, namespaceName, schemaGroupName, parameters).GetAwaiter().GetResult());
 }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of the resource group within the azure subscription.
 /// </param>
 /// <param name='namespaceName'>
 /// The Namespace name
 /// </param>
 /// <param name='schemaGroupName'>
 /// The Schema Group name
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to create an Event Hub resource.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <SchemaGroup> CreateOrUpdateAsync(this ISchemaRegistryOperations operations, string resourceGroupName, string namespaceName, string schemaGroupName, SchemaGroup parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, namespaceName, schemaGroupName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }