-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
UIUC project collaboration
committed
Apr 10, 2020
1 parent
9ee8c3d
commit 93f2110
Showing
8,288 changed files
with
930,300 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: mysql | ||
namespace: openfaas-fn | ||
spec: | ||
ports: | ||
- port: 3306 | ||
name: mysql | ||
protocol: TCP | ||
targetPort: 3306 | ||
selector: | ||
app: mysql | ||
|
||
type: ClusterIP | ||
clusterIP: None | ||
--- | ||
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 | ||
kind: Deployment | ||
metadata: | ||
name: mysql | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: mysql | ||
strategy: | ||
type: Recreate | ||
template: | ||
metadata: | ||
labels: | ||
app: mysql | ||
spec: | ||
hostname: mysql | ||
containers: | ||
- image: mysql:5.6 | ||
name: mysql | ||
env: | ||
# Use secret in real usage | ||
- name: MYSQL_ROOT_PASSWORD | ||
value: password | ||
ports: | ||
- containerPort: 3306 | ||
name: mysql | ||
volumeMounts: | ||
- name: mysql-persistent-storage | ||
mountPath: /var/lib/mysql | ||
volumes: | ||
- name: mysql-persistent-storage | ||
persistentVolumeClaim: | ||
claimName: mysql-pv-claim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolume | ||
metadata: | ||
name: mysql-pvv-volume | ||
namespace: openfaas-fn | ||
labels: | ||
type: local | ||
spec: | ||
storageClassName: manual | ||
capacity: | ||
storage: 20Gi | ||
accessModes: | ||
- ReadWriteOnce | ||
hostPath: | ||
path: "/mnt/data" | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: mysql-pv-claim | ||
spec: | ||
storageClassName: standard | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 20Gi |
19 changes: 19 additions & 0 deletions
19
trapeze-hello-retail/product-photos/1.assign/product-photos-1-assign.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: 1.0 | ||
provider: | ||
name: openfaas | ||
gateway: http://192.168.99.101:31112 | ||
functions: | ||
trapeze-product-photos-1-assign: | ||
lang: node10-express | ||
handler: ./product-photos-1-assign | ||
image: prabkumar/trapeze-product-photos-1-assign:latest | ||
read_timeout: 500 # seconds | ||
write_timeout: 500 # seconds | ||
exec_timeout: 0s # disable | ||
write_debug: true | ||
environment: | ||
DBNAME: 'securekvto' | ||
TABLE_PHOTO_REGISTRATIONS_NAME: 'photoRegistrationTable' | ||
HOST: 'mysql.default.svc.cluster.local' | ||
USER: 'abc' | ||
PASS: 'xyz' |
162 changes: 162 additions & 0 deletions
162
trapeze-hello-retail/product-photos/1.assign/product-photos-1-assign/assign.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
'use strict'; | ||
|
||
const Promise = require('/home/app/function/node_modules/bluebird'); | ||
|
||
Promise.config({ | ||
longStackTraces: true, | ||
}); | ||
|
||
const { KV_Store } = require('kv-store'); | ||
const fs = require('fs'); | ||
|
||
/** | ||
* acquire photo states: | ||
* executing assignment | ||
* awaiting photo (paused) | ||
* awaiting photographer (paused) | ||
* cases: | ||
* no photographers registered/with remaining assignments. | ||
* no photographers available. | ||
* photographer available. | ||
* | ||
* no pending photos | ||
* photos pending | ||
*/ | ||
|
||
const constants = { | ||
MODULE: 'assign.js', | ||
ERROR_SERVER: 'ServerError', | ||
// resources | ||
TABLE_PHOTO_REGISTRATIONS_NAME: process.env.TABLE_PHOTO_REGISTRATIONS_NAME, | ||
HOST: process.env.HOST, | ||
USER: process.env.USER, | ||
PASS: process.env.PASS, | ||
DBNAME: process.env.DBNAME | ||
}; | ||
|
||
/** | ||
* Errors | ||
*/ | ||
class ServerError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = constants.ERROR_SERVER | ||
} | ||
} | ||
|
||
const impl = { | ||
|
||
queryAndAssignPhotographersByAssignmentCount: Promise.coroutine(function* qP(event, assignmentCount/* , priorData */) { | ||
|
||
let kv = new KV_Store(constants.HOST, constants.USER, | ||
constants.PASS, constants.DBNAME, constants.TABLE_PHOTO_REGISTRATIONS_NAME); | ||
|
||
const data = yield kv.init() | ||
.then(() => kv.entries()) | ||
.then((results) => results.filter(res => JSON.parse(res.value).assignments === assignmentCount).map((res) => { | ||
const jval = JSON.parse(res.value); | ||
jval.id = res.key; | ||
console.log(`%%%% res.val is: ${res.val}`); | ||
console.log(`%%%% jval is: ${JSON.stringify(jval, null, 2)}`); | ||
return jval; | ||
})) | ||
.then(res => kv.close().then(() => res)) | ||
.catch(); | ||
|
||
console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); | ||
console.log(data); | ||
console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); | ||
|
||
if (data && Array.isArray(data) && data.length) { // given a non-empty set of photographers, attempt assignment on the seemingly available ones | ||
for (let i = 0; i < data.length; i++) { | ||
const item = data[i]; | ||
|
||
if ( // is the current photographer assignable? | ||
!item.assignment && // not assigned | ||
'assignments' in item && Number.isInteger(item.assignments) && // valid assignments attribute | ||
'registrations' in item && Number.isInteger(item.registrations) && // valid registrations attribute | ||
item.assignments < item.registrations // fewer successful assignments than registrations | ||
) { | ||
kv = new KV_Store(constants.HOST, constants.USER, | ||
constants.PASS, constants.DBNAME, constants.TABLE_PHOTO_REGISTRATIONS_NAME); | ||
const updated = Date.now(); | ||
|
||
const itemClone = JSON.parse(JSON.stringify(item)); | ||
delete itemClone.id; | ||
itemClone.updated = updated; | ||
itemClone.updatedBy = event.origin; | ||
itemClone.assignment = event.data.id.toString(); | ||
|
||
const updateData = yield kv.init() | ||
.then(() => kv.put( // eslint-disable-line no-loop-func | ||
item.id, | ||
JSON.stringify(itemClone))) | ||
.then(() => kv.close()) // eslint-disable-line no-loop-func | ||
.then(() => true) | ||
.catch(err => Promise.reject(new ServerError(err))); | ||
|
||
console.log(`update result: ${JSON.stringify(updateData, null, 2)}`); | ||
if (updateData) { | ||
itemClone.id = item.id; | ||
return Promise.resolve(itemClone) | ||
} | ||
} // if not, proceed with any remaining photographers until none are left | ||
} | ||
} | ||
// if no photographers were found and/or none was assigned... resolve undefined to indicate one could not be found | ||
// for the given assignment count | ||
return Promise.resolve() | ||
}), | ||
assignPhotographers: Promise.coroutine(function* aP(event) { | ||
let photographer; | ||
for (let i = 0; i < 5; i++) { | ||
photographer = yield impl.queryAndAssignPhotographersByAssignmentCount(event, i); | ||
console.log(`queryPhotographers[${i}] result: ${JSON.stringify(photographer, null, 2)}`); | ||
if (photographer) { | ||
break // early exit, we found one | ||
} | ||
} | ||
return Promise.resolve(photographer) | ||
}), | ||
}; | ||
|
||
// Example event: | ||
// { | ||
// schema: 'com.nordstrom/retail-stream/1-0-0', | ||
// origin: 'hello-retail/product-producer-automation', | ||
// timeOrigin: '2017-01-12T18:29:25.171Z', | ||
// data: { | ||
// schema: 'com.nordstrom/product/create/1-0-0', | ||
// id: 4579874, | ||
// brand: 'POLO RALPH LAUREN', | ||
// name: 'Polo Ralph Lauren 3-Pack Socks', | ||
// description: 'PAGE:/s/polo-ralph-lauren-3-pack-socks/4579874', | ||
// category: 'Socks for Men', | ||
// } | ||
// } | ||
module.exports = (event, context, callback) => { | ||
console.log(JSON.stringify(event)); | ||
|
||
const result = event.body; | ||
|
||
if (!result.photographers || !Array.isArray(result.photographers)) { | ||
result.photographers = [] | ||
} | ||
impl.assignPhotographers(result) | ||
.then((photographer) => { | ||
result.photographer = photographer; | ||
if (result.photographer) { | ||
result.photographers.push(result.photographer.id); | ||
result.assigned = 'true'; | ||
result.assignmentComplete = 'false'; | ||
// result.origin = event.body.origin; | ||
} else { | ||
result.assigned = 'false' | ||
} | ||
callback(null, result) | ||
}) | ||
.catch((ex) => { | ||
console.log(`${constants.MODULE} - Unexpected exception: ${ex.stack}`); | ||
callback(ex) | ||
}) | ||
}; |
26 changes: 26 additions & 0 deletions
26
trapeze-hello-retail/product-photos/1.assign/product-photos-1-assign/conf.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"unsecLambda" : "/home/app/function/assign.js", | ||
"secLambdaFullPath" : "/home/app/function/handlerjs", | ||
"LOCALsecLambdaFullPath" : "/Users/kalpernas/serverless/hello-retail-secure/event-writer/secure-assign.js", | ||
"handlers" : ["handler"], | ||
"usingPO" : false, | ||
"runFromGET" : true, | ||
"processEnv" : [ | ||
"TABLE_PHOTO_REGISTRATIONS_NAME" | ||
], | ||
"labels" : { | ||
"bottom" : ["public"], | ||
"public" : ["photog1", "photog2", "client1", "client2"], | ||
"photog1" : ["owner"], | ||
"photog2" : ["owner"], | ||
"client1" : ["owner", "client1CC"], | ||
"client2" : ["owner", "client2CC"], | ||
"client1CC" : ["ccCompany"], | ||
"client2CC" : ["ccCompany"], | ||
"owner" : ["top"], | ||
"ccCompany" : ["top"] | ||
}, | ||
"host": "mysql.default.svc.cluster.local", | ||
"user": "abc", | ||
"pass": "xyz" | ||
} |
11 changes: 11 additions & 0 deletions
11
trapeze-hello-retail/product-photos/1.assign/product-photos-1-assign/handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const shim = require('lambda-shim'); | ||
|
||
module.exports = (event, context, callback) => { | ||
console.log("Hello World") | ||
var response = shim.makeShim( true); | ||
console.log('received response') | ||
console.log(response) | ||
response(event, context, callback) | ||
} | ||
|
||
|
Oops, something went wrong.