Skip to content

Commit e39f3fb

Browse files
authored
Added --vector-optimized and --graph-analytics-plugin flags (#114)
* Added `--vector-optimized` and `--graph-analytics-plugin` flags * Add validation for type and graph analytics plugin
1 parent b862b42 commit e39f3fb

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Added
2+
body: Added boolean `--vector-optimized` and `--graph-analytics-plugin` flags for instance creation
3+
time: 2025-02-27T16:17:57.308325Z

neo4j-cli/aura/internal/subcommands/instance/create.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package instance
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"net/http"
78

@@ -22,6 +23,8 @@ func NewCreateCmd(cfg *clicfg.Config) *cobra.Command {
2223
tenantId string
2324
cloudProvider flags.CloudProvider
2425
customerManagedKeyId string
26+
vectorOptimized bool
27+
graphAnalyticsPlugin bool
2528
await bool
2629
)
2730

@@ -34,6 +37,8 @@ func NewCreateCmd(cfg *clicfg.Config) *cobra.Command {
3437
tenantIdFlag = "tenant-id"
3538
cloudProviderFlag = "cloud-provider"
3639
customerManagedKeyIdFlag = "customer-managed-key-id"
40+
vectorOptimizedFlag = "vector-optimized"
41+
graphAnalyticsPluginFlag = "graph-analytics-plugin"
3742
awaitFlag = "await"
3843
)
3944

@@ -72,6 +77,10 @@ For Enterprise instances you can specify a --customer-managed-key-id flag to use
7277
return fmt.Errorf(`invalid argument "%s" for "--version" flag: must be one of "4" or "5"`, version)
7378
}
7479

80+
if graphAnalyticsPlugin && _type != "professional-db" {
81+
return errors.New(`"--graph-analytics-plugin" flag can only be set when "--type" flag is set to "professional-db"`)
82+
}
83+
7584
if cfg.Aura.DefaultTenant() == "" {
7685
cmd.MarkFlagRequired(tenantIdFlag)
7786
}
@@ -101,6 +110,11 @@ For Enterprise instances you can specify a --customer-managed-key-id flag to use
101110
} else {
102111
body["memory"] = memory
103112
body["region"] = region
113+
body["vector_optimized"] = vectorOptimized
114+
}
115+
116+
if _type == "professional-db" {
117+
body["graph_analytics_plugin"] = graphAnalyticsPlugin
104118
}
105119

106120
if customerManagedKeyId != "" {
@@ -157,6 +171,11 @@ For Enterprise instances you can specify a --customer-managed-key-id flag to use
157171
cmd.Flags().Var(&cloudProvider, cloudProviderFlag, "The cloud provider hosting the instance.")
158172

159173
cmd.Flags().StringVar(&customerManagedKeyId, customerManagedKeyIdFlag, "", "An optional customer managed key to be used for instance creation.")
174+
175+
cmd.Flags().BoolVar(&vectorOptimized, vectorOptimizedFlag, false, "An optional vector optimization configuration to be set during instance creation")
176+
177+
cmd.Flags().BoolVar(&graphAnalyticsPlugin, graphAnalyticsPluginFlag, false, "An optional graph analytics plugin configuration to be set during instance creation")
178+
160179
cmd.Flags().BoolVar(&await, awaitFlag, false, "Waits until created instance is ready.")
161180

162181
return cmd

neo4j-cli/aura/internal/subcommands/instance/create_test.go

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ func TestCreateProfessionalInstance(t *testing.T) {
6262
"cloud_provider": "gcp",
6363
"region": "europe-west1",
6464
"type": "professional-db",
65-
"name": "Instance01"
65+
"name": "Instance01",
66+
"vector_optimized": false
6667
}
6768
}`)
6869

6970
helper.ExecuteCommand("instance create --region europe-west1 --name Instance01 --type professional-db --tenant-id YOUR_TENANT_ID --cloud-provider gcp --memory 4GB")
7071

7172
mockHandler.AssertCalledTimes(1)
7273
mockHandler.AssertCalledWithMethod(http.MethodPost)
73-
mockHandler.AssertCalledWithBody(`{"cloud_provider":"gcp","memory":"4GB","name":"Instance01","region":"europe-west1","tenant_id":"YOUR_TENANT_ID","type":"professional-db","version":"5"}`)
74+
mockHandler.AssertCalledWithBody(`{"cloud_provider":"gcp","memory":"4GB","name":"Instance01","region":"europe-west1","tenant_id":"YOUR_TENANT_ID","type":"professional-db","version":"5","vector_optimized":false,"graph_analytics_plugin":false}`)
7475

7576
helper.AssertOutJson(`{
7677
"data": {
@@ -82,7 +83,49 @@ func TestCreateProfessionalInstance(t *testing.T) {
8283
"region": "europe-west1",
8384
"tenant_id": "YOUR_TENANT_ID",
8485
"type": "professional-db",
85-
"username": "neo4j"
86+
"username": "neo4j",
87+
"vector_optimized": false
88+
}
89+
}`)
90+
}
91+
92+
func TestCreateProfessionalInstanceVectorOptimizedGraphAnalyticsPlugin(t *testing.T) {
93+
helper := testutils.NewAuraTestHelper(t)
94+
defer helper.Close()
95+
96+
mockHandler := helper.NewRequestHandlerMock("/v1/instances", http.StatusAccepted, `{
97+
"data": {
98+
"id": "db1d1234",
99+
"connection_url": "YOUR_CONNECTION_URL",
100+
"username": "neo4j",
101+
"password": "letMeIn123!",
102+
"tenant_id": "YOUR_TENANT_ID",
103+
"cloud_provider": "gcp",
104+
"region": "europe-west1",
105+
"type": "professional-db",
106+
"name": "Instance01",
107+
"vector_optimized": true
108+
}
109+
}`)
110+
111+
helper.ExecuteCommand("instance create --region europe-west1 --name Instance01 --type professional-db --tenant-id YOUR_TENANT_ID --cloud-provider gcp --memory 4GB --vector-optimized --graph-analytics-plugin")
112+
113+
mockHandler.AssertCalledTimes(1)
114+
mockHandler.AssertCalledWithMethod(http.MethodPost)
115+
mockHandler.AssertCalledWithBody(`{"cloud_provider":"gcp","memory":"4GB","name":"Instance01","region":"europe-west1","tenant_id":"YOUR_TENANT_ID","type":"professional-db","version":"5","vector_optimized":true,"graph_analytics_plugin":true}`)
116+
117+
helper.AssertOutJson(`{
118+
"data": {
119+
"cloud_provider": "gcp",
120+
"connection_url": "YOUR_CONNECTION_URL",
121+
"id": "db1d1234",
122+
"name": "Instance01",
123+
"password": "letMeIn123!",
124+
"region": "europe-west1",
125+
"tenant_id": "YOUR_TENANT_ID",
126+
"type": "professional-db",
127+
"username": "neo4j",
128+
"vector_optimized": true
86129
}
87130
}`)
88131
}
@@ -157,6 +200,20 @@ func TestCreateProfessionalInstanceInvalidInstanceType(t *testing.T) {
157200
`)
158201
}
159202

203+
func TestCreateProfessionalInstanceInvalidVersion(t *testing.T) {
204+
helper := testutils.NewAuraTestHelper(t)
205+
defer helper.Close()
206+
207+
mockHandler := helper.NewRequestHandlerMock("/v1/instances", http.StatusOK, "")
208+
209+
helper.ExecuteCommand("instance create --region europe-west1 --name Instance01 --type professional-db --memory 1GB --cloud-provider gcp --tenant-id YOUR_TENANT_ID --version 6")
210+
211+
mockHandler.AssertCalledTimes(0)
212+
213+
helper.AssertErr(`Error: invalid argument "6" for "--version" flag: must be one of "4" or "5"
214+
`)
215+
}
216+
160217
func TestCreateFreeInstanceWithMemory(t *testing.T) {
161218
helper := testutils.NewAuraTestHelper(t)
162219
defer helper.Close()
@@ -199,6 +256,20 @@ func TestCreateFreeInstanceWithCloudProvider(t *testing.T) {
199256
`)
200257
}
201258

259+
func TestCreateFreeInstanceWithGraphAnalyticsPlugin(t *testing.T) {
260+
helper := testutils.NewAuraTestHelper(t)
261+
defer helper.Close()
262+
263+
mockHandler := helper.NewRequestHandlerMock("/v1/instances", http.StatusOK, "")
264+
265+
helper.ExecuteCommand("instance create --name Instance01 --type free-db --graph-analytics-plugin --tenant-id YOUR_TENANT_ID")
266+
267+
mockHandler.AssertCalledTimes(0)
268+
269+
helper.AssertErr(`Error: "--graph-analytics-plugin" flag can only be set when "--type" flag is set to "professional-db"
270+
`)
271+
}
272+
202273
func TestCreateInstanceError(t *testing.T) {
203274
testCases := []struct {
204275
statusCode int
@@ -272,7 +343,7 @@ func TestInstanceWithCmkId(t *testing.T) {
272343

273344
mockHandler.AssertCalledTimes(1)
274345
mockHandler.AssertCalledWithMethod(http.MethodPost)
275-
mockHandler.AssertCalledWithBody(`{"cloud_provider":"gcp","memory":"16GB","name":"Instance01","region":"europe-west1","tenant_id":"YOUR_TENANT_ID","type":"enterprise-db","version":"5","customer_managed_key_id":"UUID_OF_YOUR_KEY"}`)
346+
mockHandler.AssertCalledWithBody(`{"cloud_provider":"gcp","memory":"16GB","name":"Instance01","region":"europe-west1","tenant_id":"YOUR_TENANT_ID","type":"enterprise-db","version":"5","customer_managed_key_id":"UUID_OF_YOUR_KEY","vector_optimized":false}`)
276347

277348
helper.AssertOutJson(`{
278349
"data": {

0 commit comments

Comments
 (0)