Skip to content

Commit

Permalink
feat: add async pipeline trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
pinglin committed Jun 26, 2022
1 parent 6f689d9 commit 6d39b0a
Show file tree
Hide file tree
Showing 12 changed files with 560 additions and 176 deletions.
17 changes: 15 additions & 2 deletions integration-test/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,23 @@ export const detSyncMultiModelInstRecipe = {

export const dstCSVConnID = "some-cool-name-for-dst-csv-connector"

export const detAsyncRecipe = {
export const detAsyncSingleModelInstRecipe = {
recipe: {
source: "source-connectors/source-http",
model_instances: [`models/${model_id}/instances/${model_instance_id}`],
model_instances: [
`models/${model_id}/instances/${model_instance_id}`
],
destination:`destination-connectors/${dstCSVConnID}`
},
};

export const detAsyncMultiModelInstRecipe = {
recipe: {
source: "source-connectors/source-http",
model_instances: [
`models/${model_id}/instances/${model_instance_id}`,
`models/${model_id}/instances/${model_instance_id}`,
],
destination:`destination-connectors/${dstCSVConnID}`
},
};
10 changes: 5 additions & 5 deletions integration-test/rest-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ export function CheckList() {
[`GET /v1alpha/pipelines?filter=mode=MODE_SYNC%20AND%20recipe.source=%22${srcConnPermalink}%22 response pipelines.length > 0`]: (r) => r.json().pipelines.length > 0,
});

check(http.request("GET", `${pipelineHost}/v1alpha/pipelines?filter=mode=MODE_SYNC%20AND%20recipe.source=%22${srcConnPermalink}%22%20AND%20recipe.model_instances:%22${modelInstPermalink}%22`, null, {headers: {"Content-Type": "application/json",}}), {
[`GET /v1alpha/pipelines?filter=mode=MODE_SYNC%20AND%20recipe.source=%22${srcConnPermalink}%22%20AND%20recipe.model_instances:%22${modelInstPermalink}%22 response 200`]: (r) => r.status == 200,
[`GET /v1alpha/pipelines?filter=mode=MODE_SYNC%20AND%20recipe.source=%22${srcConnPermalink}%22%20AND%20recipe.model_instances:%22${modelInstPermalink}%22 response pipelines.length > 0`]: (r) => r.json().pipelines.length > 0,
check(http.request("GET", `${pipelineHost}/v1alpha/pipelines?filter=mode=MODE_SYNC%20AND%20recipe.destination=%22${dstConnPermalink}%22%20AND%20recipe.model_instances:%22${modelInstPermalink}%22`, null, {headers: {"Content-Type": "application/json",}}), {
[`GET /v1alpha/pipelines?filter=mode=MODE_SYNC%20AND%20recipe.source=%22${dstConnPermalink}%22%20AND%20recipe.model_instances:%22${modelInstPermalink}%22 response 200`]: (r) => r.status == 200,
[`GET /v1alpha/pipelines?filter=mode=MODE_SYNC%20AND%20recipe.source=%22${dstConnPermalink}%22%20AND%20recipe.model_instances:%22${modelInstPermalink}%22 response pipelines.length > 0`]: (r) => r.json().pipelines.length > 0,
});

// Delete the pipelines
Expand Down Expand Up @@ -474,7 +474,7 @@ export function CheckUpdateState() {
{
id: randomString(10),
},
constant.detAsyncRecipe
constant.detAsyncSingleModelInstRecipe
)

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines`, JSON.stringify(reqBodyAsync), {
Expand All @@ -483,7 +483,7 @@ export function CheckUpdateState() {
},
}), {
"POST /v1alpha/pipelines async pipeline creation response status is 201": (r) => r.status === 201,
"POST /v1alpha/pipelines async pipeline creation response pipeline state ACTIVE": (r) => r.json().pipeline.state === "STATE_INACTIVE",
"POST /v1alpha/pipelines async pipeline creation response pipeline state ACTIVE": (r) => r.json().pipeline.state === "STATE_ACTIVE",
});

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines/${reqBodyAsync.id}:activate`, null, {
Expand Down
256 changes: 256 additions & 0 deletions integration-test/rest-trigger-async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
import http from "k6/http";
import encoding from "k6/encoding";

import { FormData } from "https://jslib.k6.io/formdata/0.0.2/index.js";
import { check, group } from "k6";
import { randomString } from "https://jslib.k6.io/k6-utils/1.1.0/index.js";

import * as constant from "./const.js"

export function CheckTriggerAsyncSingleImageSingleModelInst() {

var reqBody = Object.assign(
{
id: randomString(10),
description: randomString(50),
},
constant.detAsyncSingleModelInstRecipe
);

group("Pipelines API: Trigger an async pipeline for single image and single model instance", () => {

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines`, JSON.stringify(reqBody), {
headers: {
"Content-Type": "application/json",
},
}), {
"POST /v1alpha/pipelines response status is 201": (r) => r.status === 201,
});

var payloadImageURL = {
inputs: [
{
image_url: "https://artifacts.instill.tech/dog.jpg",
}
]
};

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}:trigger`, JSON.stringify(payloadImageURL), {
headers: {
"Content-Type": "application/json",
},
}), {
[`POST /v1alpha/pipelines/${reqBody.id}:trigger (url) response status is 200`]: (r) => r.status === 200,
});

var payloadImageBase64 = {
inputs: [
{
imageBase64: encoding.b64encode(constant.dogImg, "b"),
}
]
};

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}:trigger`, JSON.stringify(payloadImageBase64), {
headers: {
"Content-Type": "application/json",
},
}), {
[`POST /v1alpha/pipelines/${reqBody.id}:trigger (base64) response status is 200`]: (r) => r.status === 200,
});

const fd = new FormData();
fd.append("file", http.file(constant.dogImg));
check(http.request("POST", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}:trigger-multipart`, fd.body(), {
headers: {
"Content-Type": `multipart/form-data; boundary=${fd.boundary}`,
},
}), {
[`POST /v1alpha/pipelines/${reqBody.id}:trigger (multipart) response status is 200`]: (r) => r.status === 200,
});

});

// Delete the pipeline
check(http.request("DELETE", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}`, null, {
headers: {
"Content-Type": "application/json",
},
}), {
[`DELETE /v1alpha/pipelines/${reqBody.id} response status 204`]: (r) => r.status === 204,
});
}

export function CheckTriggerAsyncMultiImageSingleModelInst() {
var reqBody = Object.assign(
{
id: randomString(10),
description: randomString(50),
},
constant.detAsyncSingleModelInstRecipe
);

group("Pipelines API: Trigger an async pipeline for multiple images and single model instance", () => {

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines`, JSON.stringify(reqBody), {
headers: {
"Content-Type": "application/json",
},
}), {
"POST /v1alpha/pipelines response status is 201": (r) => r.status === 201,
});

var payloadImageURL = {
inputs: [
{
image_url: "https://artifacts.instill.tech/dog.jpg",
},
{
image_url: "https://artifacts.instill.tech/dog.jpg",
},
{
image_url: "https://artifacts.instill.tech/dog.jpg",
}
]
};

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}:trigger`, JSON.stringify(payloadImageURL), {
headers: {
"Content-Type": "application/json",
},
}), {
[`POST /v1alpha/pipelines/${reqBody.id}:trigger (url) response status is 200`]: (r) => r.status === 200,
});

var payloadImageBase64 = {
inputs: [
{
imageBase64: encoding.b64encode(constant.dogImg, "b"),
},
{
imageBase64: encoding.b64encode(constant.dogImg, "b"),
},
{
imageBase64: encoding.b64encode(constant.dogImg, "b"),
}
]
};

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}:trigger`, JSON.stringify(payloadImageBase64), {
headers: {
"Content-Type": "application/json",
},
}), {
[`POST /v1alpha/pipelines/${reqBody.id}:trigger (base64) response status is 200`]: (r) => r.status === 200,
});

const fd = new FormData();
fd.append("file", http.file(constant.dogImg));
fd.append("file", http.file(constant.dogImg));
fd.append("file", http.file(constant.dogImg));
check(http.request("POST", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}:trigger-multipart`, fd.body(), {
headers: {
"Content-Type": `multipart/form-data; boundary=${fd.boundary}`,
},
}), {
[`POST /v1alpha/pipelines/${reqBody.id}:trigger (multipart) response status is 200`]: (r) => r.status === 200,
});

});

// Delete the pipeline
check(http.request("DELETE", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}`, null, {
headers: {
"Content-Type": "application/json",
},
}), {
[`DELETE /v1alpha/pipelines/${reqBody.id} response status 204`]: (r) => r.status === 204,
});
}

export function CheckTriggerAsyncMultiImageMultiModelInst() {
var reqBody = Object.assign(
{
id: randomString(10),
description: randomString(50),
},
constant.detAsyncMultiModelInstRecipe
);

group("Pipelines API: Trigger an async pipeline for multiple images and multiple model instances", () => {

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines`, JSON.stringify(reqBody), {
headers: {
"Content-Type": "application/json",
},
}), {
"POST /v1alpha/pipelines response status is 201": (r) => r.status === 201,
});

var payloadImageURL = {
inputs: [
{
image_url: "https://artifacts.instill.tech/dog.jpg",
},
{
image_url: "https://artifacts.instill.tech/dog.jpg",
},
{
image_url: "https://artifacts.instill.tech/dog.jpg",
}
]
};

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}:trigger`, JSON.stringify(payloadImageURL), {
headers: {
"Content-Type": "application/json",
},
}), {
[`POST /v1alpha/pipelines/${reqBody.id}:trigger (url) response status is 200`]: (r) => r.status === 200,
});

var payloadImageBase64 = {
inputs: [
{
imageBase64: encoding.b64encode(constant.dogImg, "b"),
},
{
imageBase64: encoding.b64encode(constant.dogImg, "b"),
},
{
imageBase64: encoding.b64encode(constant.dogImg, "b"),
}
]
};

check(http.request("POST", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}:trigger`, JSON.stringify(payloadImageBase64), {
headers: {
"Content-Type": "application/json",
},
}), {
[`POST /v1alpha/pipelines/${reqBody.id}:trigger (base64) response status is 200`]: (r) => r.status === 200,
});

const fd = new FormData();
fd.append("file", http.file(constant.dogImg));
fd.append("file", http.file(constant.dogImg));
fd.append("file", http.file(constant.dogImg));
check(http.request("POST", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}:trigger-multipart`, fd.body(), {
headers: {
"Content-Type": `multipart/form-data; boundary=${fd.boundary}`,
},
}), {
[`POST /v1alpha/pipelines/${reqBody.id}:trigger (multipart) response status is 200`]: (r) => r.status === 200,
});

});

// Delete the pipeline
check(http.request("DELETE", `${pipelineHost}/v1alpha/pipelines/${reqBody.id}`, null, {
headers: {
"Content-Type": "application/json",
},
}), {
[`DELETE /v1alpha/pipelines/${reqBody.id} response status 204`]: (r) => r.status === 204,
});
}
Loading

0 comments on commit 6d39b0a

Please sign in to comment.