Skip to content

Commit

Permalink
Merge branch 'main' into review-result-reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ruokun-niu authored Jan 3, 2025
2 parents e6a3053 + d8f41cb commit d81c696
Show file tree
Hide file tree
Showing 58 changed files with 2,677 additions and 1,831 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/vsce.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2024 The Drasi Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Download and Publish Visual Studio Code Extension

on:
workflow_dispatch:
inputs:
version:
description: 'Version of the extension'
required: true


jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install VSCE
run: npm install @vscode/vsce --save-dev
- name: Download VSIX from GitHub Release
run: |
curl -L -o drasi.vsix https://github.com/drasi-project/drasi-platform/releases/download/${{ github.event.inputs.version }}/drasi-${{ github.event.inputs.version }}.vsix
- name: Publish
run: |
npx vsce publish -p ${{ secrets.VSCE_TOKEN }} --packagePath drasi.vsix
7 changes: 6 additions & 1 deletion cli/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ Usage examples:
output := output.NewTaskOutput()
defer output.Close()

if err := installer.Install(local, registry, version, output, namespace); err != nil {
daprRegistry, err := cmd.Flags().GetString("dapr-registry")
if err != nil {
return err
}
if err := installer.Install(local, registry, version, output, namespace, daprRegistry); err != nil {
return err
}

Expand All @@ -106,5 +110,6 @@ Usage examples:
initCommand.Flags().StringP("namespace", "n", "drasi-system", "Kubernetes namespace to install Drasi into.")
initCommand.Flags().String("dapr-runtime-version", "1.10.0", "Dapr runtime version to install.")
initCommand.Flags().String("dapr-sidecar-version", "1.9.0", "Dapr sidecar (daprd) version to install.")
initCommand.Flags().String("dapr-registry", "docker.io/daprio", "Container registry to pull Dapr images from.")
return initCommand
}
9 changes: 6 additions & 3 deletions cli/service/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ func MakeInstaller(namespace string) (*Installer, error) {
return &result, nil
}

func (t *Installer) Install(localMode bool, acr string, version string, output output.TaskOutput, namespace string) error {
func (t *Installer) Install(localMode bool, acr string, version string, output output.TaskOutput, namespace string, daprRegistry string) error {
daprInstalled, err := t.checkDaprInstallation(output)
if err != nil {
return err
}

if !daprInstalled {
if err = t.installDapr(output); err != nil {
if err = t.installDapr(output, daprRegistry); err != nil {
return err
}
}
Expand Down Expand Up @@ -541,7 +542,7 @@ func (t *Installer) waitForDeployment(selector string, output output.TaskOutput)
return nil
}

func (t *Installer) installDapr(output output.TaskOutput) error {
func (t *Installer) installDapr(output output.TaskOutput, daprRegistry string) error {
output.AddTask("Dapr-Install", "Installing Dapr...")

ns := "dapr-system"
Expand Down Expand Up @@ -602,6 +603,8 @@ func (t *Installer) installDapr(output output.TaskOutput) error {
installClient.CreateNamespace = true
installClient.Timeout = time.Duration(120) * time.Second

helmChart.Values["global"].(map[string]interface{})["registry"] = daprRegistry

helmChart.Values["dapr_operator"] = make(map[string]interface{})
if daprOperator, ok := helmChart.Values["dapr_operator"].(map[string]interface{}); ok {
daprOperator["watchInterval"] = "10s"
Expand Down
48 changes: 21 additions & 27 deletions cli/service/resources/default-reaction-providers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,17 @@ spec:
config_schema:
type: object
properties:
Brokers:
brokers:
type: array
topic:
type: string
Topic:
saslUsername:
type: string
saslPassword:
type: string
IncludeKey:
type: boolean
default: true
IncludeSchemas:
type: boolean
default: true
required:
- Brokers
- Topic
- brokers
- topic
---
apiVersion: v1
kind: ReactionProvider
Expand All @@ -64,13 +62,12 @@ spec:
config_schema:
type: object
properties:
EventGridUri:
eventGridUri:
type: string
EventGridKey:
eventGridKey:
type: string
required:
- EventGridUri
- EventGridKey
- eventGridUri
---
apiVersion: v1
kind: ReactionProvider
Expand All @@ -79,26 +76,23 @@ spec:
config_schema:
type: object
properties:
AddedResultCommand:
type: string
UpdatedResultCommand:
addedResultCommand:
type: string
DatabaseHost:
updatedResultCommand:
type: string
DatabasePrimaryKey:
deletedResultCommand:
type: string
DatabaseName:
gremlinHost:
type: string
DatabaseContainerName:
gremlinPort:
type: number
gremlinPassword:
type: string
DatabasePort:
gremlinUsername:
type: string
required:
- DatabaseHost
- DatabasePrimaryKey
- DatabaseName
- DatabaseContainerName
- DatabasePort
- gremlinHost
- gremlinPort
services:
reaction:
image: reaction-gremlin
Expand Down
10 changes: 6 additions & 4 deletions dev-tools/vscode/drasi/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "drasi",
"displayName": "drasi",
"publisher": "drasi-project",
"description": "",
"version": "0.0.3",
"publisher": "DrasiProject",
"description": "The Drasi Visual Studio Code Extension",
"version": "0.1.6",
"icon": "resources/drasi.png",
"repository": {
"type": "git",
"url": "https://github.com/drasi-project/drasi-platform.git"
Expand Down Expand Up @@ -151,7 +152,8 @@
"watch": "node ./esbuild.js --watch",
"lint": "eslint src --ext ts",
"pretest": "npm run compile",
"test": "node ./out/test/runTest.js"
"test": "node ./out/test/runTest.js",
"deploy": "vsce publish"
},
"devDependencies": {
"@types/glob": "^8.0.1",
Expand Down
Binary file added dev-tools/vscode/drasi/resources/drasi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: Reaction
apiVersion: v1
name: e2e-gremlin-reaction
spec:
kind: Gremlin
queries:
query3-deletion:
properties:
deletedResultCommand: g.addV('Item').property('ItemId', @Id).property('Name',@Name)
gremlinHost: gremlin-server.default.svc.cluster.local
gremlinPort: 8182
137 changes: 137 additions & 0 deletions e2e-tests/03-gremlin-reaction-scenario/gremlin-reaction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* Copyright 2024 The Drasi Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const yaml = require('js-yaml');
const fs = require('fs');
const PortForward = require('../fixtures/port-forward');
const deployResources = require("../fixtures/deploy-resources");
const deleteResources = require("../fixtures/delete-resources");
const pg = require('pg');
const gremlin = require('gremlin');


let postgresPortForward = new PortForward("postgres03", 5432);

let postgresClient = new pg.Client({
database: "test-db",
host: "127.0.0.1",
user: "test",
password: "test",
});
let gremlinPortForward = new PortForward("gremlin-server", 8182);
let gremlinClient;
let gremlinDriverConnection;

beforeAll(async () => {
// Setting up the postgres database for the Source
const postgresResources = yaml.loadAll(fs.readFileSync(__dirname + '/resources.yaml', 'utf8'));
await deployResources(postgresResources);

postgresClient.port = await postgresPortForward.start();
await postgresClient.connect();
await new Promise(r => setTimeout(r, 15000));



// Setting up the Gremlin database
const gremlinResources = yaml.loadAll(fs.readFileSync(__dirname + '/gremlin-resources.yaml', 'utf8'));
await deployResources(gremlinResources);
await new Promise(r => setTimeout(r, 15000));


let gremlinPort = await gremlinPortForward.start();

// gremlin-server-service.default.svc.cluster.local
const traversal = gremlin.process.AnonymousTraversalSource.traversal;
gremlinDriverConnection = new gremlin.driver.DriverRemoteConnection(`ws://localhost:${gremlinPort}/gremlin`, {});
gremlinClient = traversal().withRemote(gremlinDriverConnection);
}, 150000);


test('Test Gremlin Reaction - AddedResultCommand', async () => {
const gremlinReaction = yaml.loadAll(fs.readFileSync(__dirname + '/gremlin-reaction.yaml', 'utf8'));
await deployResources(gremlinReaction);

await postgresClient.query(`INSERT INTO "Item" ("ItemId", "Name", "Category") VALUES (4, 'Drasi', '3')`);
await waitForCondition(async () => {
const result = await gremlinClient.V().has('ItemId', '4').hasNext();
return result;
}, 1000,30000)
.then(() => {
expect(true).toBeTruthy();
})
.catch(() => {
expect(false).toBeTruthy();
});
}, 140000);

test('Test Gremlin Reaction - deletedResultCommand', async () => {
const gremlinReaction = yaml.loadAll(fs.readFileSync(__dirname + '/gremlin-reaction-deletion.yaml', 'utf8'));
await deployResources(gremlinReaction);

await postgresClient.query(`DELETE FROM "Item" WHERE "ItemId" = 5`);
await waitForCondition(async () => {
const result = await gremlinClient.V().has('ItemId', '5').hasNext();
return result;
}, 1000,30000)
.then(() => {
expect(true).toBeTruthy();
})
.catch(() => {
expect(false).toBeTruthy();
});
}, 140000);


afterAll(async () => {
await postgresClient.end();
postgresPortForward.stop();

gremlinPortForward.stop();
gremlinDriverConnection.close();

const postgresResources = yaml.loadAll(fs.readFileSync(__dirname + '/resources.yaml', 'utf8'));
await deleteResources(postgresResources);


const gremlinResources = yaml.loadAll(fs.readFileSync(__dirname + '/gremlin-resources.yaml', 'utf8'));
await deleteResources(gremlinResources);

const gremlinReaction = yaml.loadAll(fs.readFileSync(__dirname + '/gremlin-reaction.yaml', 'utf8'));
await deleteResources(gremlinReaction);

const gremlinReactionDeletion = yaml.loadAll(fs.readFileSync(__dirname + '/gremlin-reaction-deletion.yaml', 'utf8'));
await deleteResources(gremlinReactionDeletion);
});


function waitForCondition(checkFn, interval = 1000, timeout = 30000) {
return new Promise((resolve, reject) => {
let elapsedTime = 0;

const intervalId = setInterval(async () => {
if (await checkFn()) {
clearInterval(intervalId);
resolve();
} else if (elapsedTime >= timeout) {
clearInterval(intervalId);
reject(new Error("Timed out waiting for condition to be met"));
}

elapsedTime += interval;
}, interval);
});
}
11 changes: 11 additions & 0 deletions e2e-tests/03-gremlin-reaction-scenario/gremlin-reaction.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: Reaction
apiVersion: v1
name: e2e-gremlin-reaction-deletion
spec:
kind: Gremlin
queries:
query3:
properties:
addedResultCommand: g.addV('Item').property('ItemId', @Id).property('Name',@Name)
gremlinHost: gremlin-server.default.svc.cluster.local
gremlinPort: 8182
Loading

0 comments on commit d81c696

Please sign in to comment.