public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                DatabaseName      = resourceIdentifier.ResourceName;
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
            }

            if (!string.IsNullOrEmpty(Name))
            {
                GremlinGraphGetResults gremlinGraphGetResults = CosmosDBManagementClient.GremlinResources.GetGremlinGraphWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name).GetAwaiter().GetResult().Body;
                WriteObject(new PSGremlinGraphGetResults(gremlinGraphGetResults));

                if (Detailed)
                {
                    ThroughputSettingsGetResults throughputSettingsGetResults = CosmosDBManagementClient.GremlinResources.GetGremlinGraphThroughputWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name).GetAwaiter().GetResult().Body;
                    WriteObject(throughputSettingsGetResults);
                }
            }
            else
            {
                IEnumerable <GremlinGraphGetResults> gremlinGraphs = CosmosDBManagementClient.GremlinResources.ListGremlinGraphsWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName).GetAwaiter().GetResult().Body;

                foreach (GremlinGraphGetResults gremlinGraph in gremlinGraphs)
                {
                    WriteObject(new PSGremlinGraphGetResults(gremlinGraph));
                }
            }

            return;
        }
 private void VerifyGremlinGraphCreation(GremlinGraphGetResults gremlinGraphGetResults, GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters)
 {
     Assert.Equal(gremlinGraphGetResults.Resource.Id, gremlinGraphCreateUpdateParameters.Resource.Id);
     Assert.Equal(gremlinGraphGetResults.Resource.IndexingPolicy.IndexingMode.ToLower(), gremlinGraphCreateUpdateParameters.Resource.IndexingPolicy.IndexingMode.ToLower());
     Assert.Equal(gremlinGraphGetResults.Resource.PartitionKey.Kind, gremlinGraphCreateUpdateParameters.Resource.PartitionKey.Kind);
     Assert.Equal(gremlinGraphGetResults.Resource.PartitionKey.Paths, gremlinGraphCreateUpdateParameters.Resource.PartitionKey.Paths);
     Assert.Equal(gremlinGraphGetResults.Resource.DefaultTtl, gremlinGraphCreateUpdateParameters.Resource.DefaultTtl);
 }
예제 #3
0
 public PSGremlinGraphGetResults(GremlinGraphGetResults gremlinGraphGetResults)
 {
     Name     = gremlinGraphGetResults.Name;
     Id       = gremlinGraphGetResults.Id;
     Location = gremlinGraphGetResults.Location;
     Tags     = gremlinGraphGetResults.Tags;
     Resource = new PSGremlinGraphGetPropertiesResource(gremlinGraphGetResults.Resource);
 }
        public async Task GremlinGraphListTests()
        {
            List <GremlinGraphGetResults> gremlinGraphs = await CosmosDBManagementClient.GremlinResources.ListGremlinGraphsAsync(resourceGroupName, databaseAccountName, databaseName).ToEnumerableAsync();

            Assert.NotNull(gremlinGraphs);
            Assert.AreEqual(gremlinGraphs.Count, 1);
            GremlinGraphGetResults gremlinGraphGetResults = await CosmosDBManagementClient.GremlinResources.GetGremlinGraphAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraphName);

            VerifyEqualGremlinGraphs(gremlinGraphs[0], gremlinGraphGetResults);
        }
        private void VerifyEqualGremlinGraphs(GremlinGraphGetResults expectedValue, GremlinGraphGetResults actualValue)
        {
            Assert.AreEqual(expectedValue.Id, actualValue.Id);
            Assert.AreEqual(expectedValue.Name, actualValue.Name);
            Assert.AreEqual(expectedValue.Location, actualValue.Location);
            Assert.AreEqual(expectedValue.Tags, actualValue.Tags);
            Assert.AreEqual(expectedValue.Type, actualValue.Type);

            Assert.AreEqual(expectedValue.Options, actualValue.Options);

            Assert.AreEqual(expectedValue.Resource.Id, actualValue.Resource.Id);
            Assert.AreEqual(expectedValue.Resource.Rid, actualValue.Resource.Rid);
            Assert.AreEqual(expectedValue.Resource.Ts, actualValue.Resource.Ts);
            Assert.AreEqual(expectedValue.Resource.Etag, actualValue.Resource.Etag);

            Assert.AreEqual(expectedValue.Resource.ConflictResolutionPolicy.ConflictResolutionPath, actualValue.Resource.ConflictResolutionPolicy.ConflictResolutionPath);
            Assert.AreEqual(expectedValue.Resource.ConflictResolutionPolicy.ConflictResolutionPath, actualValue.Resource.ConflictResolutionPolicy.ConflictResolutionPath);
            Assert.AreEqual(expectedValue.Resource.ConflictResolutionPolicy.Mode, actualValue.Resource.ConflictResolutionPolicy.Mode);

            Assert.AreEqual(expectedValue.Resource.DefaultTtl, actualValue.Resource.DefaultTtl);

            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.Automatic, actualValue.Resource.IndexingPolicy.Automatic);

            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.IncludedPaths.Count, actualValue.Resource.IndexingPolicy.IncludedPaths.Count);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.IncludedPaths[0].Path, actualValue.Resource.IndexingPolicy.IncludedPaths[0].Path);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.IncludedPaths[0].Indexes, actualValue.Resource.IndexingPolicy.IncludedPaths[0].Indexes);

            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.ExcludedPaths.Count, actualValue.Resource.IndexingPolicy.ExcludedPaths.Count);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.ExcludedPaths[0].Path, actualValue.Resource.IndexingPolicy.ExcludedPaths[0].Path);

            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes.Count, actualValue.Resource.IndexingPolicy.CompositeIndexes.Count);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes[0].Count, actualValue.Resource.IndexingPolicy.CompositeIndexes[0].Count);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes[0][0].Path, actualValue.Resource.IndexingPolicy.CompositeIndexes[0][0].Path);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes[0][0].Order, actualValue.Resource.IndexingPolicy.CompositeIndexes[0][0].Order);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes[0][1].Path, actualValue.Resource.IndexingPolicy.CompositeIndexes[0][1].Path);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes[0][1].Order, actualValue.Resource.IndexingPolicy.CompositeIndexes[0][1].Order);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes[1].Count, actualValue.Resource.IndexingPolicy.CompositeIndexes[1].Count);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes[1][0].Path, actualValue.Resource.IndexingPolicy.CompositeIndexes[1][0].Path);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes[1][0].Order, actualValue.Resource.IndexingPolicy.CompositeIndexes[1][0].Order);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes[1][1].Path, actualValue.Resource.IndexingPolicy.CompositeIndexes[1][1].Path);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.CompositeIndexes[1][1].Order, actualValue.Resource.IndexingPolicy.CompositeIndexes[1][1].Order);

            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.IndexingMode, actualValue.Resource.IndexingPolicy.IndexingMode);

            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.SpatialIndexes.Count, actualValue.Resource.IndexingPolicy.SpatialIndexes.Count);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.SpatialIndexes[0].Path, actualValue.Resource.IndexingPolicy.SpatialIndexes[0].Path);
            Assert.AreEqual(expectedValue.Resource.IndexingPolicy.SpatialIndexes[0].Types, actualValue.Resource.IndexingPolicy.SpatialIndexes[0].Types);

            Assert.AreEqual(expectedValue.Resource.PartitionKey.Kind, actualValue.Resource.PartitionKey.Kind);
            Assert.AreEqual(expectedValue.Resource.PartitionKey.Paths, actualValue.Resource.PartitionKey.Paths);
            Assert.AreEqual(expectedValue.Resource.PartitionKey.Version, actualValue.Resource.PartitionKey.Version);

            Assert.AreEqual(expectedValue.Resource.UniqueKeyPolicy.UniqueKeys.Count, actualValue.Resource.UniqueKeyPolicy.UniqueKeys.Count);
            Assert.AreEqual(expectedValue.Resource.UniqueKeyPolicy.UniqueKeys[0].Paths, actualValue.Resource.UniqueKeyPolicy.UniqueKeys[0].Paths);
        }
        public void GraphCRUDTests()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                fixture.Init(context);

                string databaseAccountName = this.fixture.GetDatabaseAccountName(TestFixture.AccountType.Gremlin);

                var gremlinClient = this.fixture.CosmosDBManagementClient.GremlinResources;

                string databaseName     = TestUtilities.GenerateName(prefix: "gremlinDb");
                string databaseName2    = TestUtilities.GenerateName(prefix: "gremlinDb");
                string gremlinGraphName = TestUtilities.GenerateName(prefix: "gremlinGraph");

                const string gremlinThroughputType = "Microsoft.DocumentDB/databaseAccounts/gremlinDatabases/throughputSettings";

                const int sampleThroughput = 700;

                Dictionary <string, string> additionalProperties = new Dictionary <string, string>
                {
                    { "foo", "bar" }
                };
                Dictionary <string, string> tags = new Dictionary <string, string>
                {
                    { "key3", "value3" },
                    { "key4", "value4" }
                };

                GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters = new GremlinDatabaseCreateUpdateParameters
                {
                    Resource = new GremlinDatabaseResource {
                        Id = databaseName
                    },
                    Options = new CreateUpdateOptions()
                };

                GremlinDatabaseGetResults gremlinDatabaseGetResults = gremlinClient.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(
                    this.fixture.ResourceGroupName,
                    databaseAccountName,
                    databaseName,
                    gremlinDatabaseCreateUpdateParameters
                    ).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults);
                Assert.Equal(databaseName, gremlinDatabaseGetResults.Name);

                GremlinDatabaseGetResults gremlinDatabaseGetResults1 = gremlinClient.GetGremlinDatabaseWithHttpMessagesAsync(
                    this.fixture.ResourceGroupName,
                    databaseAccountName,
                    databaseName
                    ).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults1);
                Assert.Equal(databaseName, gremlinDatabaseGetResults1.Name);

                VerifyEqualGremlinDatabases(gremlinDatabaseGetResults, gremlinDatabaseGetResults1);

                GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters2 = new GremlinDatabaseCreateUpdateParameters
                {
                    Location = this.fixture.Location,
                    Tags     = tags,
                    Resource = new GremlinDatabaseResource {
                        Id = databaseName2
                    },
                    Options = new CreateUpdateOptions
                    {
                        Throughput = sampleThroughput
                    }
                };

                GremlinDatabaseGetResults gremlinDatabaseGetResults2 = gremlinClient.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(
                    this.fixture.ResourceGroupName,
                    databaseAccountName,
                    databaseName2,
                    gremlinDatabaseCreateUpdateParameters2
                    ).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults2);
                Assert.Equal(databaseName2, gremlinDatabaseGetResults2.Name);

                IEnumerable <GremlinDatabaseGetResults> gremlinDatabases = gremlinClient.ListGremlinDatabasesWithHttpMessagesAsync(
                    this.fixture.ResourceGroupName,
                    databaseAccountName
                    ).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabases);

                ThroughputSettingsGetResults throughputSettingsGetResults = gremlinClient.GetGremlinDatabaseThroughputWithHttpMessagesAsync(
                    this.fixture.ResourceGroupName,
                    databaseAccountName,
                    databaseName2
                    ).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal(throughputSettingsGetResults.Resource.Throughput, sampleThroughput);
                Assert.Equal(gremlinThroughputType, throughputSettingsGetResults.Type);

                GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters = new GremlinGraphCreateUpdateParameters
                {
                    Resource = new GremlinGraphResource
                    {
                        Id           = gremlinGraphName,
                        DefaultTtl   = -1,
                        PartitionKey = new ContainerPartitionKey
                        {
                            Kind  = "Hash",
                            Paths = new List <string> {
                                "/address"
                            }
                        },
                        IndexingPolicy = new IndexingPolicy
                        {
                            Automatic     = true,
                            IndexingMode  = IndexingMode.Consistent,
                            IncludedPaths = new List <IncludedPath>
                            {
                                new IncludedPath {
                                    Path = "/*"
                                }
                            },
                            ExcludedPaths = new List <ExcludedPath>
                            {
                                new ExcludedPath {
                                    Path = "/pathToNotIndex/*"
                                }
                            },
                            CompositeIndexes = new List <IList <CompositePath> >
                            {
                                new List <CompositePath>
                                {
                                    new CompositePath {
                                        Path = "/orderByPath1", Order = CompositePathSortOrder.Ascending
                                    },
                                    new CompositePath {
                                        Path = "/orderByPath2", Order = CompositePathSortOrder.Descending
                                    }
                                },
                                new List <CompositePath>
                                {
                                    new CompositePath {
                                        Path = "/orderByPath3", Order = CompositePathSortOrder.Ascending
                                    },
                                    new CompositePath {
                                        Path = "/orderByPath4", Order = CompositePathSortOrder.Descending
                                    }
                                }
                            }
                        }
                    },
                    Options = new CreateUpdateOptions
                    {
                        Throughput = sampleThroughput
                    }
                };

                GremlinGraphGetResults gremlinGraphGetResults = gremlinClient.CreateUpdateGremlinGraphWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, gremlinGraphName, gremlinGraphCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinGraphGetResults);
                VerifyGremlinGraphCreation(gremlinGraphGetResults, gremlinGraphCreateUpdateParameters);

                IEnumerable <GremlinGraphGetResults> gremlinGraphs = gremlinClient.ListGremlinGraphsWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinGraphs);

                foreach (GremlinGraphGetResults gremlinGraph in gremlinGraphs)
                {
                    gremlinClient.DeleteGremlinGraphWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, gremlinGraph.Name);
                }

                foreach (GremlinDatabaseGetResults gremlinDatabase in gremlinDatabases)
                {
                    gremlinClient.DeleteGremlinDatabaseWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, gremlinDatabase.Name);
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                DatabaseName      = resourceIdentifier.ResourceName;
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
            }

            List <string> Paths = new List <string>();

            foreach (string path in PartitionKeyPath)
            {
                Paths.Add(path);
            }

            GremlinGraphResource gremlinGraphResource = new GremlinGraphResource
            {
                Id           = Name,
                PartitionKey = new ContainerPartitionKey
                {
                    Kind    = PartitionKeyKind,
                    Paths   = Paths,
                    Version = PartitionKeyVersion
                }
            };

            if (UniqueKeyPolicy != null)
            {
                UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy
                {
                    UniqueKeys = new List <UniqueKey>()
                };

                foreach (PSUniqueKey uniqueKey in UniqueKeyPolicy.UniqueKeys)
                {
                    UniqueKey key = new UniqueKey
                    {
                        Paths = new List <string>()
                    };

                    foreach (string path in uniqueKey.Paths)
                    {
                        key.Paths.Add(path);
                    }

                    uniqueKeyPolicy.UniqueKeys.Add(key);
                }

                gremlinGraphResource.UniqueKeyPolicy = uniqueKeyPolicy;
            }

            if (TtlInSeconds != null)
            {
                gremlinGraphResource.DefaultTtl = TtlInSeconds;
            }

            if (ConflictResolutionPolicy != null)
            {
                ConflictResolutionPolicyMode = ConflictResolutionPolicy.Mode;

                if (ConflictResolutionPolicy.ConflictResolutionPath != null)
                {
                    ConflictResolutionPolicyPath = ConflictResolutionPolicy.ConflictResolutionPath;
                }

                if (ConflictResolutionPolicy.ConflictResolutionProcedure != null)
                {
                    ConflictResolutionPolicyProcedure = ConflictResolutionPolicy.ConflictResolutionProcedure;
                }
            }

            if (ConflictResolutionPolicyMode != null)
            {
                ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy
                {
                    Mode = ConflictResolutionPolicyMode
                };

                if (ConflictResolutionPolicyMode.Equals("LastWriterWins", StringComparison.OrdinalIgnoreCase))
                {
                    conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicyPath;
                }
                else if (ConflictResolutionPolicyMode.Equals("Custom", StringComparison.OrdinalIgnoreCase))
                {
                    conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicyProcedure;
                }

                gremlinGraphResource.ConflictResolutionPolicy = conflictResolutionPolicy;
            }

            if (IndexingPolicy != null)
            {
                IndexingPolicy indexingPolicy = new IndexingPolicy
                {
                    Automatic    = IndexingPolicy.Automatic,
                    IndexingMode = IndexingPolicy.IndexingMode,
                };

                if (IndexingPolicy.IncludedPaths != null)
                {
                    IList <IncludedPath> includedPaths = new List <IncludedPath>();
                    foreach (PSIncludedPath pSIncludedPath in IndexingPolicy.IncludedPaths)
                    {
                        includedPaths.Add(new IncludedPath
                        {
                            Path    = pSIncludedPath.Path,
                            Indexes = PSIncludedPath.ConvertPSIndexesToIndexes(pSIncludedPath.Indexes)
                        });
                    }

                    indexingPolicy.IncludedPaths = new List <IncludedPath>(includedPaths);
                }

                if (IndexingPolicy.ExcludedPaths != null && IndexingPolicy.ExcludedPaths.Count > 0)
                {
                    IList <ExcludedPath> excludedPaths = new List <ExcludedPath>();
                    foreach (PSExcludedPath pSExcludedPath in IndexingPolicy.ExcludedPaths)
                    {
                        excludedPaths.Add(new ExcludedPath {
                            Path = pSExcludedPath.Path
                        });
                    }

                    indexingPolicy.ExcludedPaths = new List <ExcludedPath>(excludedPaths);
                }

                if (IndexingPolicy.CompositeIndexes != null)
                {
                    IList <IList <CompositePath> > compositeIndexes = new List <IList <CompositePath> >();
                    foreach (IList <PSCompositePath> pSCompositePathList in IndexingPolicy.CompositeIndexes)
                    {
                        IList <CompositePath> compositePathList = new List <CompositePath>();
                        foreach (PSCompositePath pSCompositePath in pSCompositePathList)
                        {
                            compositePathList.Add(new CompositePath {
                                Order = pSCompositePath.Order, Path = pSCompositePath.Path
                            });
                        }

                        compositeIndexes.Add(compositePathList);
                    }

                    indexingPolicy.CompositeIndexes = new List <IList <CompositePath> >(compositeIndexes);
                }

                if (IndexingPolicy.SpatialIndexes != null && IndexingPolicy.SpatialIndexes.Count > 0)
                {
                    IList <SpatialSpec> spatialIndexes = new List <SpatialSpec>();

                    foreach (PSSpatialSpec pSSpatialSpec in IndexingPolicy.SpatialIndexes)
                    {
                        spatialIndexes.Add(new SpatialSpec {
                            Path = pSSpatialSpec.Path, Types = pSSpatialSpec.Types
                        });
                    }

                    indexingPolicy.SpatialIndexes = new List <SpatialSpec>(spatialIndexes);
                }

                gremlinGraphResource.IndexingPolicy = indexingPolicy;
            }

            CreateUpdateOptions options = new CreateUpdateOptions();

            if (Throughput != null)
            {
                options.Throughput = Throughput.ToString();
            }

            GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters = new GremlinGraphCreateUpdateParameters
            {
                Resource = gremlinGraphResource,
                Options  = options
            };

            if (ShouldProcess(Name, "Setting CosmosDB Gremlin Graph"))
            {
                GremlinGraphGetResults gremlinGraphGetResults = CosmosDBManagementClient.GremlinResources.CreateUpdateGremlinGraphWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, gremlinGraphCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSGremlinGraphGetResults(gremlinGraphGetResults));
            }

            return;
        }
        public async Task GremlinGraphCreateUpdateTests()
        {
            IList <IncludedPath> includedPath = new List <IncludedPath> {
                new IncludedPath {
                    Path = "/*"
                }
            };
            IList <ExcludedPath> excludedPaths = new List <ExcludedPath> {
                new ExcludedPath {
                    Path = "/pathToNotIndex/*"
                }
            };
            IList <IList <CompositePath> > compositeIndexes = new List <IList <CompositePath> >
            {
                new List <CompositePath>
                {
                    new CompositePath {
                        Path = "/orderByPath1", Order = CompositePathSortOrder.Ascending
                    },
                    new CompositePath {
                        Path = "/orderByPath2", Order = CompositePathSortOrder.Descending
                    }
                },
                new List <CompositePath>
                {
                    new CompositePath {
                        Path = "/orderByPath3", Order = CompositePathSortOrder.Ascending
                    },
                    new CompositePath {
                        Path = "/orderByPath4", Order = CompositePathSortOrder.Descending
                    }
                }
            };
            IList <SpatialSpec> spatialIndexes = new List <SpatialSpec> {
                new SpatialSpec("/*", new List <SpatialType> {
                    new SpatialType("Point")
                })
            };

            IndexingPolicy indexingPolicy = new IndexingPolicy(true, IndexingMode.Consistent, includedPath, excludedPaths, compositeIndexes, spatialIndexes);

            ContainerPartitionKey containerPartitionKey = new ContainerPartitionKey(new List <string> {
                "/address"
            }, "Hash", null);
            IList <string> paths = new List <string>()
            {
                "/testpath"
            };
            UniqueKey         uk         = new UniqueKey(paths);
            IList <UniqueKey> uniqueKeys = new List <UniqueKey>();

            uniqueKeys.Add(uk);
            UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy(uniqueKeys);

            ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy(new ConflictResolutionMode("LastWriterWins"), "/path", "");
            CreateUpdateOptions      createUpdateOptions      = new CreateUpdateOptions(sampleThroughput, new AutoscaleSettings());

            GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters = new GremlinGraphCreateUpdateParameters(new GremlinGraphResource(gremlinGraphName, indexingPolicy, containerPartitionKey, -1, uniqueKeyPolicy, conflictResolutionPolicy), createUpdateOptions);

            Response <GremlinGraphGetResults> gremlinResponse = await WaitForCompletionAsync(await CosmosDBManagementClient.GremlinResources.StartCreateUpdateGremlinGraphAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraphName, gremlinGraphCreateUpdateParameters));

            Assert.NotNull(gremlinResponse);
            GremlinGraphGetResults gremlinGraphGetResults = gremlinResponse.Value;

            Assert.NotNull(gremlinGraphGetResults);

            VerifyGremlinGraphCreation(gremlinGraphGetResults, gremlinGraphCreateUpdateParameters);

            var throughputResponse = CosmosDBManagementClient.GremlinResources.GetGremlinGraphThroughputAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraphName);
            ThroughputSettingsGetResults throughputSettingsGetResults = throughputResponse.ConfigureAwait(false).GetAwaiter().GetResult();

            Assert.NotNull(throughputSettingsGetResults);
            Assert.NotNull(throughputSettingsGetResults.Name);
            Assert.AreEqual(throughputSettingsGetResults.Resource.Throughput, sampleThroughput);
            Assert.AreEqual(gremlinGraphsThroughputType, throughputSettingsGetResults.Type);

            CreateUpdateOptions createUpdateOptions2 = new CreateUpdateOptions(sampleThroughput2, new AutoscaleSettings());
            GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters2 = new GremlinGraphCreateUpdateParameters(new GremlinGraphResource(gremlinGraphName, indexingPolicy, containerPartitionKey, -1, uniqueKeyPolicy, conflictResolutionPolicy), createUpdateOptions2);

            Response <GremlinGraphGetResults> gremlinResponse2 = await WaitForCompletionAsync(await CosmosDBManagementClient.GremlinResources.StartCreateUpdateGremlinGraphAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraphName, gremlinGraphCreateUpdateParameters2));

            Assert.NotNull(gremlinResponse2);
            GremlinGraphGetResults gremlinGraphGetResults2 = gremlinResponse2.Value;

            Assert.NotNull(gremlinGraphGetResults2);

            VerifyGremlinGraphCreation(gremlinGraphGetResults2, gremlinGraphCreateUpdateParameters2);

            var throughputResponse2 = CosmosDBManagementClient.GremlinResources.GetGremlinGraphThroughputAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraphName);
            ThroughputSettingsGetResults throughputSettingsGetResults2 = throughputResponse2.ConfigureAwait(false).GetAwaiter().GetResult();

            Assert.NotNull(throughputSettingsGetResults2);
            Assert.NotNull(throughputSettingsGetResults2.Name);
            Assert.AreEqual(throughputSettingsGetResults2.Resource.Throughput, sampleThroughput2);
            Assert.AreEqual(gremlinGraphsThroughputType, throughputSettingsGetResults2.Type);
        }
예제 #9
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                DatabaseName      = resourceIdentifier.ResourceName;
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
            }

            GremlinGraphGetResults readGremlinGraphGetResults = null;

            try
            {
                readGremlinGraphGetResults = CosmosDBManagementClient.GremlinResources.GetGremlinGraph(ResourceGroupName, AccountName, DatabaseName, Name);
            }
            catch (CloudException e)
            {
                if (e.Response.StatusCode != System.Net.HttpStatusCode.NotFound)
                {
                    throw;
                }
            }

            if (readGremlinGraphGetResults != null)
            {
                throw new ConflictingResourceException(message: string.Format(ExceptionMessage.Conflict, Name));
            }

            List <string>        Paths = new List <string>(PartitionKeyPath);
            GremlinGraphResource gremlinGraphResource = new GremlinGraphResource
            {
                Id           = Name,
                PartitionKey = new ContainerPartitionKey
                {
                    Kind    = PartitionKeyKind,
                    Paths   = Paths,
                    Version = PartitionKeyVersion
                }
            };

            if (UniqueKeyPolicy != null)
            {
                gremlinGraphResource.UniqueKeyPolicy = PSUniqueKeyPolicy.ToSDKModel(UniqueKeyPolicy);
            }

            if (TtlInSeconds != null)
            {
                gremlinGraphResource.DefaultTtl = TtlInSeconds;
            }

            if (ConflictResolutionPolicy != null)
            {
                gremlinGraphResource.ConflictResolutionPolicy = PSConflictResolutionPolicy.ToSDKModel(ConflictResolutionPolicy);
            }
            else if (ConflictResolutionPolicyMode != null)
            {
                ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy
                {
                    Mode = ConflictResolutionPolicyMode
                };

                if (ConflictResolutionPolicyMode.Equals(ConflictResolutionMode.LastWriterWins, StringComparison.OrdinalIgnoreCase))
                {
                    conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicyPath;
                }
                else if (ConflictResolutionPolicyMode.Equals(ConflictResolutionMode.Custom, StringComparison.OrdinalIgnoreCase))
                {
                    conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicyProcedure;
                }

                gremlinGraphResource.ConflictResolutionPolicy = conflictResolutionPolicy;
            }

            if (IndexingPolicy != null)
            {
                gremlinGraphResource.IndexingPolicy = PSIndexingPolicy.ToSDKModel(IndexingPolicy);
            }

            CreateUpdateOptions options = ThroughputHelper.PopulateCreateUpdateOptions(Throughput, AutoscaleMaxThroughput);

            GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters = new GremlinGraphCreateUpdateParameters
            {
                Resource = gremlinGraphResource,
                Options  = options
            };

            if (ShouldProcess(Name, "Creating a new CosmosDB Gremlin Graph"))
            {
                GremlinGraphGetResults gremlinGraphGetResults = CosmosDBManagementClient.GremlinResources.CreateUpdateGremlinGraphWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, gremlinGraphCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSGremlinGraphGetResults(gremlinGraphGetResults));
            }

            return;
        }
예제 #10
0
        public void GraphCRUDTests()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                // Create client
                CosmosDBManagementClient cosmosDBManagementClient = CosmosDBTestUtilities.GetCosmosDBClient(context, handler1);

                bool isDatabaseNameExists = cosmosDBManagementClient.DatabaseAccounts.CheckNameExistsWithHttpMessagesAsync(databaseAccountName).GetAwaiter().GetResult().Body;

                if (!isDatabaseNameExists)
                {
                    return;
                }

                GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters = new GremlinDatabaseCreateUpdateParameters
                {
                    Resource = new GremlinDatabaseResource {
                        Id = databaseName
                    },
                    Options = new CreateUpdateOptions
                    {
                        AdditionalProperties = additionalProperties
                    }
                };

                GremlinDatabaseGetResults gremlinDatabaseGetResults = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, gremlinDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults);
                Assert.Equal(databaseName, gremlinDatabaseGetResults.Name);

                GremlinDatabaseGetResults gremlinDatabaseGetResults1 = cosmosDBManagementClient.GremlinResources.GetGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults1);
                Assert.Equal(databaseName, gremlinDatabaseGetResults1.Name);

                VerifyEqualGremlinDatabases(gremlinDatabaseGetResults, gremlinDatabaseGetResults1);

                GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters2 = new GremlinDatabaseCreateUpdateParameters
                {
                    Location = location,
                    Tags     = tags,
                    Resource = new GremlinDatabaseResource {
                        Id = databaseName2
                    },
                    Options = new CreateUpdateOptions
                    {
                        Throughput = sampleThroughput.ToString()
                    }
                };

                GremlinDatabaseGetResults gremlinDatabaseGetResults2 = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2, gremlinDatabaseCreateUpdateParameters2).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults2);
                Assert.Equal(databaseName2, gremlinDatabaseGetResults2.Name);

                IEnumerable <GremlinDatabaseGetResults> gremlinDatabases = cosmosDBManagementClient.GremlinResources.ListGremlinDatabasesWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabases);

                ThroughputSettingsGetResults throughputSettingsGetResults = cosmosDBManagementClient.GremlinResources.GetGremlinDatabaseThroughputWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal(throughputSettingsGetResults.Resource.Throughput, sampleThroughput);
                Assert.Equal(graphThroughputType, throughputSettingsGetResults.Type);

                GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters = new GremlinGraphCreateUpdateParameters
                {
                    Resource = new GremlinGraphResource
                    {
                        Id           = gremlinGraphName,
                        DefaultTtl   = -1,
                        PartitionKey = new ContainerPartitionKey
                        {
                            Kind  = "Hash",
                            Paths = new List <string> {
                                "/address"
                            }
                        },
                        IndexingPolicy = new IndexingPolicy
                        {
                            Automatic     = true,
                            IndexingMode  = IndexingMode.Consistent,
                            IncludedPaths = new List <IncludedPath>
                            {
                                new IncludedPath {
                                    Path = "/*"
                                }
                            },
                            ExcludedPaths = new List <ExcludedPath>
                            {
                                new ExcludedPath {
                                    Path = "/pathToNotIndex/*"
                                }
                            },
                            CompositeIndexes = new List <IList <CompositePath> >
                            {
                                new List <CompositePath>
                                {
                                    new CompositePath {
                                        Path = "/orderByPath1", Order = CompositePathSortOrder.Ascending
                                    },
                                    new CompositePath {
                                        Path = "/orderByPath2", Order = CompositePathSortOrder.Descending
                                    }
                                },
                                new List <CompositePath>
                                {
                                    new CompositePath {
                                        Path = "/orderByPath3", Order = CompositePathSortOrder.Ascending
                                    },
                                    new CompositePath {
                                        Path = "/orderByPath4", Order = CompositePathSortOrder.Descending
                                    }
                                }
                            }
                        }
                    },
                    Options = new CreateUpdateOptions
                    {
                        Throughput = sampleThroughput.ToString()
                    }
                };

                GremlinGraphGetResults gremlinGraphGetResults = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinGraphWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraphName, gremlinGraphCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinGraphGetResults);
                VerifyGremlinGraphCreation(gremlinGraphGetResults, gremlinGraphCreateUpdateParameters);

                IEnumerable <GremlinGraphGetResults> gremlinGraphs = cosmosDBManagementClient.GremlinResources.ListGremlinGraphsWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinGraphs);

                foreach (GremlinGraphGetResults gremlinGraph in gremlinGraphs)
                {
                    cosmosDBManagementClient.GremlinResources.DeleteGremlinGraphWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraph.Name);
                }

                foreach (GremlinDatabaseGetResults gremlinDatabase in gremlinDatabases)
                {
                    cosmosDBManagementClient.GremlinResources.DeleteGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, gremlinDatabase.Name);
                }
            }
        }
예제 #11
0
        private GremlinGraphGetResults CreateGremlinResources(CosmosDBManagementClient cosmosDBManagementClient, string databaseAccountName, string databaseName, string graphName)
        {
            GremlinDatabaseGetResults databaseGetResults = null;

            try
            {
                databaseGetResults = cosmosDBManagementClient.GremlinResources.GetGremlinDatabase(this.fixture.ResourceGroupName, databaseAccountName, databaseName);
            }
            catch (Exception) { }

            if (databaseGetResults == null)
            {
                GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters = new GremlinDatabaseCreateUpdateParameters
                {
                    Resource = new GremlinDatabaseResource {
                        Id = databaseName
                    },
                    Options = new CreateUpdateOptions()
                };

                databaseGetResults = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabase(
                    this.fixture.ResourceGroupName,
                    databaseAccountName,
                    databaseName,
                    gremlinDatabaseCreateUpdateParameters);
            }

            GremlinGraphGetResults graphGetResult = null;

            try
            {
                graphGetResult = cosmosDBManagementClient.GremlinResources.GetGremlinGraph(this.fixture.ResourceGroupName, databaseAccountName, databaseName, graphName);
            }
            catch (Exception) { }

            if (graphGetResult == null)
            {
                GremlinGraphCreateUpdateParameters collectionCreateParams = new GremlinGraphCreateUpdateParameters()
                {
                    Resource = new GremlinGraphResource
                    {
                        Id           = graphName,
                        PartitionKey = new ContainerPartitionKey()
                        {
                            Kind  = "Hash",
                            Paths = new List <string> {
                                "/pk"
                            }
                        }
                    },
                    Options = new CreateUpdateOptions()
                    {
                        Throughput = 30000
                    }
                };

                graphGetResult = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinGraph(
                    this.fixture.ResourceGroupName,
                    databaseAccountName,
                    databaseName,
                    graphName,
                    collectionCreateParams);
            }

            return(graphGetResult);
        }
예제 #12
0
        public void GraphCRUDTests()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                // Create client
                CosmosDBManagementClient cosmosDBManagementClient = CosmosDBTestUtilities.GetCosmosDBClient(context, handler1);
                ResourceManagementClient resourcesClient          = CosmosDBTestUtilities.GetResourceManagementClient(context, handler2);

                string resourceGroupName   = "CosmosDBResourceGroup2510";
                string databaseAccountName = "db1002";

                bool isDatabaseNameExists = cosmosDBManagementClient.DatabaseAccounts.CheckNameExistsWithHttpMessagesAsync(databaseAccountName).GetAwaiter().GetResult().Body;

                //DatabaseAccountGetResults databaseAccount = null;
                if (!isDatabaseNameExists)
                {
                    return;
                    // SDK doesnt support creation of Cassandra, Table, Gremlin Accounts, use accounts created using Azure portal

                    // List<Location> locations = new List<Location>();
                    // locations.Add(new Location(locationName: "East US"));
                    // DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters
                    // {
                    //     Location = "EAST US",
                    //     Locations = locations
                    // };

                    //databaseAccount = cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                }

                string databaseName  = "databaseName1002";
                string databaseName2 = "databaseName21002";
                GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters = new GremlinDatabaseCreateUpdateParameters
                {
                    Resource = new GremlinDatabaseResource {
                        Id = databaseName
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                GremlinDatabaseGetResults gremlinDatabaseGetResults = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, gremlinDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults);
                Assert.Equal(databaseName, gremlinDatabaseGetResults.Name);

                GremlinDatabaseGetResults gremlinDatabaseGetResults1 = cosmosDBManagementClient.GremlinResources.GetGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults1);
                Assert.Equal(databaseName, gremlinDatabaseGetResults1.Name);

                VerifyEqualGremlinDatabases(gremlinDatabaseGetResults, gremlinDatabaseGetResults1);

                GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters2 = new GremlinDatabaseCreateUpdateParameters
                {
                    Location = "EAST US",
                    Tags     = new Dictionary <string, string>
                    {
                        { "key3", "value3" },
                        { "key4", "value4" }
                    },
                    Resource = new GremlinDatabaseResource {
                        Id = databaseName2
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                GremlinDatabaseGetResults gremlinDatabaseGetResults2 = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2, gremlinDatabaseCreateUpdateParameters2).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults2);
                Assert.Equal(databaseName2, gremlinDatabaseGetResults2.Name);

                IEnumerable <GremlinDatabaseGetResults> gremlinDatabases = cosmosDBManagementClient.GremlinResources.ListGremlinDatabasesWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabases);

                ThroughputSettingsGetResults throughputSettingsGetResults = cosmosDBManagementClient.GremlinResources.GetGremlinDatabaseThroughputWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal("Microsoft.DocumentDB/databaseAccounts/gremlinDatabases/throughputSettings", throughputSettingsGetResults.Type);

                string gremlinGraphName = "gremlinGraphName1002";

                GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters = new GremlinGraphCreateUpdateParameters
                {
                    Resource = new GremlinGraphResource
                    {
                        Id           = gremlinGraphName,
                        PartitionKey = new ContainerPartitionKey
                        {
                            Kind  = "Hash",
                            Paths = new List <string> {
                                "/address"
                            }
                        }
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                GremlinGraphGetResults gremlinGraphGetResults = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinGraphWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraphName, gremlinGraphCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinGraphGetResults);

                IEnumerable <GremlinGraphGetResults> gremlinGraphs = cosmosDBManagementClient.GremlinResources.ListGremlinGraphsWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinGraphs);

                foreach (GremlinGraphGetResults gremlinGraph in gremlinGraphs)
                {
                    cosmosDBManagementClient.GremlinResources.DeleteGremlinGraphWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraph.Name);
                }

                foreach (GremlinDatabaseGetResults gremlinDatabase in gremlinDatabases)
                {
                    cosmosDBManagementClient.GremlinResources.DeleteGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, gremlinDatabase.Name);
                }
            }
        }