Example #1
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                AccountName       = resourceIdentifier.ResourceName;
            }

            CreateUpdateOptions options = new CreateUpdateOptions();

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

            MongoDBDatabaseCreateUpdateParameters mongoDBDatabaseCreateUpdateParameters = new MongoDBDatabaseCreateUpdateParameters
            {
                Resource = new MongoDBDatabaseResource
                {
                    Id = Name
                },
                Options = options
            };

            if (ShouldProcess(Name, "Setting CosmosDB MongoDB Database"))
            {
                MongoDBDatabaseGetResults mongoDBDatabaseGetResults = CosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBDatabaseWithHttpMessagesAsync(ResourceGroupName, AccountName, Name, mongoDBDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSMongoDBDatabaseGetResults(mongoDBDatabaseGetResults));
            }

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

            IDictionary <string, string> options = new Dictionary <string, string>();

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

            TableCreateUpdateParameters tableCreateUpdateParameters = new TableCreateUpdateParameters
            {
                Resource = new TableResource
                {
                    Id = Name
                },
                Options = options
            };

            if (ShouldProcess(Name, "Setting CosmosDB Table"))
            {
                TableGetResults tableGetResults = CosmosDBManagementClient.TableResources.CreateUpdateTableWithHttpMessagesAsync(ResourceGroupName, AccountName, Name, tableCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSTableGetResults(tableGetResults));
            }

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

            CassandraTableGetResults readCassandraTableGetResults = null;

            try
            {
                readCassandraTableGetResults = CosmosDBManagementClient.CassandraResources.GetCassandraTable(ResourceGroupName, AccountName, KeyspaceName, Name);
            }
            catch (CloudException e)
            {
                if (e.Response.StatusCode != System.Net.HttpStatusCode.NotFound)
                {
                    throw;
                }
            }

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

            CreateUpdateOptions options = new CreateUpdateOptions();

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

            CassandraTableResource cassandraTableResource = new CassandraTableResource
            {
                Id         = Name,
                DefaultTtl = TtlInSeconds
            };

            cassandraTableResource.Schema = PSCassandraSchema.ToSDKModel(Schema);

            CassandraTableCreateUpdateParameters cassandraTableCreateUpdateParameters = new CassandraTableCreateUpdateParameters
            {
                Resource = cassandraTableResource,
                Options  = options
            };

            if (ShouldProcess(Name, "Creating a new CosmosDB Cassandra Table"))
            {
                CassandraTableGetResults cassandraTableGetResults = CosmosDBManagementClient.CassandraResources.CreateUpdateCassandraTableWithHttpMessagesAsync(ResourceGroupName, AccountName, KeyspaceName, Name, cassandraTableCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSCassandraTableGetResults(cassandraTableGetResults));
            }

            return;
        }
Example #4
0
        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);
            }

            MongoDBCollectionResource mongoDBCollectionResource = new MongoDBCollectionResource
            {
                Id = Name
            };

            if (Shard != null)
            {
                mongoDBCollectionResource.ShardKey = new Dictionary <string, string> {
                    { Shard, "Hash" }
                };
            }

            if (Index != null)
            {
                List <MongoIndex> Indexes = new List <MongoIndex>();
                foreach (PSMongoIndex psMongoIndex in Index)
                {
                    Indexes.Add(PSMongoIndex.ConvertPSMongoIndexToMongoIndex(psMongoIndex));
                }

                mongoDBCollectionResource.Indexes = Indexes;
            }

            CreateUpdateOptions options = new CreateUpdateOptions();

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

            MongoDBCollectionCreateUpdateParameters mongoDBCollectionCreateUpdateParameters = new MongoDBCollectionCreateUpdateParameters
            {
                Resource = mongoDBCollectionResource,
                Options  = options
            };

            if (ShouldProcess(Name, "Setting CosmosDB MongoDB Collection"))
            {
                MongoDBCollectionGetResults mongoDBCollectionGetResults = CosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBCollectionWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, mongoDBCollectionCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSMongoDBCollectionGetResults(mongoDBCollectionGetResults));
            }

            return;
        }
Example #5
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                AccountName       = resourceIdentifier.ResourceName;
            }
            else if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
                Name = resourceIdentifier.ResourceName;
            }

            TableGetResults readTableGetResults = null;

            try
            {
                readTableGetResults = CosmosDBManagementClient.TableResources.GetTable(ResourceGroupName, AccountName, Name);
            }
            catch (CloudException e)
            {
                if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new ResourceNotFoundException(message: string.Format(ExceptionMessage.NotFound, Name), innerException: e);
                }
            }

            CreateUpdateOptions options = new CreateUpdateOptions();

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

            TableCreateUpdateParameters tableCreateUpdateParameters = new TableCreateUpdateParameters
            {
                Resource = new TableResource
                {
                    Id = Name
                },
                Options = options
            };

            if (ShouldProcess(Name, "Updating an existing CosmosDB Table"))
            {
                TableGetResults tableGetResults = CosmosDBManagementClient.TableResources.CreateUpdateTableWithHttpMessagesAsync(ResourceGroupName, AccountName, Name, tableCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSTableGetResults(tableGetResults));
            }

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

            GremlinDatabaseGetResults readGremlinDatabaseGetResults = null;

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

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

            CreateUpdateOptions options = new CreateUpdateOptions();

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

            GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters = new GremlinDatabaseCreateUpdateParameters
            {
                Resource = new GremlinDatabaseResource
                {
                    Id = Name
                },
                Options = options
            };

            if (ShouldProcess(Name, "Creating a new CosmosDB Gremlin Database"))
            {
                GremlinDatabaseGetResults gremlinDatabaseGetResults = CosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(ResourceGroupName, AccountName, Name, gremlinDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSGremlinDatabaseGetResults(gremlinDatabaseGetResults));
            }

            return;
        }
Example #7
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                AccountName       = resourceIdentifier.ResourceName;
            }
            else if (ParameterSetName.Equals(ObjectParameterSet))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
                Name = resourceIdentifier.ResourceName;
            }

            CreateUpdateOptions options = new CreateUpdateOptions();

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

            GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters = new GremlinDatabaseCreateUpdateParameters
            {
                Resource = new GremlinDatabaseResource
                {
                    Id = Name
                },
                Options = options
            };

            if (ShouldProcess(Name, "Updating CosmosDB Gremlin Database"))
            {
                GremlinDatabaseGetResults gremlinDatabaseGetResults = CosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(ResourceGroupName, AccountName, Name, gremlinDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSGremlinDatabaseGetResults(gremlinDatabaseGetResults));
            }

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

            IDictionary <string, string> options = new Dictionary <string, string>();

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

            CassandraTableResource cassandraTableResource = new CassandraTableResource
            {
                Id         = Name,
                DefaultTtl = TtlInSeconds
            };

            cassandraTableResource.Schema = PSCassandraSchema.ConvertPSCassandraSchemaToCassandraSchema(Schema);

            CassandraTableCreateUpdateParameters cassandraTableCreateUpdateParameters = new CassandraTableCreateUpdateParameters
            {
                Resource = cassandraTableResource,
                Options  = options
            };

            if (ShouldProcess(Name, "Setting CosmosDB Cassandra Table"))
            {
                CassandraTableGetResults cassandraTableGetResults = CosmosDBManagementClient.CassandraResources.CreateUpdateCassandraTableWithHttpMessagesAsync(ResourceGroupName, AccountName, KeyspaceName, Name, cassandraTableCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSCassandraTableGetResults(cassandraTableGetResults));
            }

            return;
        }
        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);
            }

            SqlContainerGetResults readSqlContainerGetResults = null;

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

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

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

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

            SqlContainerResource sqlContainerResource = new SqlContainerResource
            {
                Id           = Name,
                PartitionKey = new ContainerPartitionKey
                {
                    Kind    = PartitionKeyKind,
                    Paths   = Paths,
                    Version = PartitionKeyVersion
                }
            };

            if (UniqueKeyPolicy != null)
            {
                sqlContainerResource.UniqueKeyPolicy = PSUniqueKeyPolicy.ConvertPSUniqueKeyPolicyToUniqueKeyPolicy(UniqueKeyPolicy);
            }

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

            if (ConflictResolutionPolicy != null)
            {
                sqlContainerResource.ConflictResolutionPolicy = PSConflictResolutionPolicy.ConvertPSConflictResolutionPolicyToConflictResolutionPolicy(ConflictResolutionPolicy);
            }

            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;
                }

                sqlContainerResource.ConflictResolutionPolicy = conflictResolutionPolicy;
            }

            if (IndexingPolicy != null)
            {
                sqlContainerResource.IndexingPolicy = PSIndexingPolicy.ConvertPSIndexingToIndexingPolicy(IndexingPolicy);
            }

            CreateUpdateOptions options = new CreateUpdateOptions();

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

            SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters
            {
                Resource = sqlContainerResource,
                Options  = options
            };

            if (ShouldProcess(Name, "Creating a new CosmosDB Sql Container"))
            {
                SqlContainerGetResults sqlContainerGetResults = CosmosDBManagementClient.SqlResources.CreateUpdateSqlContainerWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSSqlContainerGetResults(sqlContainerGetResults));
            }

            return;
        }
        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;
        }
Example #11
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);
            }
            else if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                Name         = resourceIdentifier.ResourceName;
                DatabaseName = ResourceIdentifierExtensions.GetMongoDBDatabaseName(resourceIdentifier);
                AccountName  = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
            }

            MongoDBCollectionGetResults readMongoDBCollectionGetResults = null;

            try
            {
                readMongoDBCollectionGetResults = CosmosDBManagementClient.MongoDBResources.GetMongoDBCollection(ResourceGroupName, AccountName, DatabaseName, Name);
            }
            catch (CloudException e)
            {
                if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new ResourceNotFoundException(message: string.Format(ExceptionMessage.NotFound, Name), innerException: e);
                }
            }

            MongoDBCollectionResource mongoDBCollectionResource = PopulateMongoDBResource(readMongoDBCollectionGetResults.Resource);

            if (Shard != null)
            {
                mongoDBCollectionResource.ShardKey = new Dictionary <string, string> {
                    { Shard, "Hash" }
                };
            }

            if (Index != null)
            {
                List <MongoIndex> Indexes = new List <MongoIndex>();
                foreach (PSMongoIndex psMongoIndex in Index)
                {
                    Indexes.Add(PSMongoIndex.ConvertPSMongoIndexToMongoIndex(psMongoIndex));
                }

                mongoDBCollectionResource.Indexes = Indexes;
            }

            CreateUpdateOptions options = new CreateUpdateOptions();

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

            MongoDBCollectionCreateUpdateParameters mongoDBCollectionCreateUpdateParameters = new MongoDBCollectionCreateUpdateParameters
            {
                Resource = mongoDBCollectionResource,
                Options  = options
            };

            if (ShouldProcess(Name, "Updating an existing CosmosDB MongoDB Collection"))
            {
                MongoDBCollectionGetResults mongoDBCollectionGetResults = CosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBCollectionWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, mongoDBCollectionCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSMongoDBCollectionGetResults(mongoDBCollectionGetResults));
            }

            return;
        }
        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);
            }
            else if (ParameterSetName.Equals(ObjectParameterSet))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                DatabaseName      = ResourceIdentifierExtensions.GetGremlinDatabaseName(resourceIdentifier);
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
                Name = resourceIdentifier.ResourceName;
            }

            GremlinGraphGetResults readGremlinGraphGetResults = null;

            try
            {
                readGremlinGraphGetResults = CosmosDBManagementClient.GremlinResources.GetGremlinGraph(ResourceGroupName, AccountName, DatabaseName, Name);
            }
            catch (CloudException e)
            {
                if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new ResourceNotFoundException(message: string.Format(ExceptionMessage.NotFound, Name), innerException: e);
                }
            }

            GremlinGraphResource gremlinGraphResource = UpdateAzCosmosDBGremlinGraph.PopulateGremlinGraphResourceResource(readGremlinGraphGetResults.Resource);

            if (PartitionKeyPath != null)
            {
                List <string> Paths = new List <string>(PartitionKeyPath);

                gremlinGraphResource.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);
            }

            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 = new CreateUpdateOptions();

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

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

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

            return;
        }
Example #13
0
        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);
            }

            SqlContainerResource sqlContainerResource = new SqlContainerResource
            {
                Id           = Name,
                PartitionKey = new ContainerPartitionKey
                {
                    Kind    = PartitionKeyKind,
                    Paths   = Paths,
                    Version = PartitionKeyVersion
                }
            };

            if (UniqueKeyPolicy != null)
            {
                UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy();

                foreach (PSSqlUniqueKey uniqueKey in UniqueKeyPolicy.UniqueKey)
                {
                    UniqueKey key = new UniqueKey(uniqueKey.Path);
                    uniqueKeyPolicy.UniqueKeys.Add(key);
                }

                sqlContainerResource.UniqueKeyPolicy = uniqueKeyPolicy;
            }

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

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

                if (ConflictResolutionPolicy.Type.Equals("LastWriterWins", StringComparison.OrdinalIgnoreCase))
                {
                    conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicy.Path;
                }
                else if (ConflictResolutionPolicy.Type.Equals("Custom", StringComparison.OrdinalIgnoreCase))
                {
                    conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicy.ConflictResolutionProcedure;
                }

                sqlContainerResource.ConflictResolutionPolicy = conflictResolutionPolicy;
            }

            if (IndexingPolicy != null)
            {
                IList <IncludedPath> includedPaths = new List <IncludedPath>();
                IList <ExcludedPath> excludedPaths = new List <ExcludedPath>();

                foreach (string path in IndexingPolicy.IncludedPaths)
                {
                    includedPaths.Add(new IncludedPath(path: path));
                }

                foreach (string path in IndexingPolicy.ExcludedPaths)
                {
                    excludedPaths.Add(new ExcludedPath(path: path));
                }

                IndexingPolicy indexingPolicy = new IndexingPolicy
                {
                    Automatic     = IndexingPolicy.Automatic,
                    IndexingMode  = IndexingPolicy.IndexingMode,
                    IncludedPaths = includedPaths,
                    ExcludedPaths = excludedPaths
                };

                sqlContainerResource.IndexingPolicy = indexingPolicy;
            }

            IDictionary <string, string> options = new Dictionary <string, string>();

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

            SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters
            {
                Resource = sqlContainerResource,
                Options  = options
            };

            if (ShouldProcess(Name, "Creating or Updating CosmosDB Sql Container"))
            {
                SqlContainerGetResults sqlContainerGetResults = CosmosDBManagementClient.SqlResources.CreateUpdateSqlContainerWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSSqlContainerGetResults(sqlContainerGetResults));
            }

            return;
        }