Skip to content

Commit

Permalink
Merge branch 'release/0.8.0'.
Browse files Browse the repository at this point in the history
  • Loading branch information
petrbroz committed May 30, 2019
2 parents 1e0e876 + 24031d8 commit 0ac12b3
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 62 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,18 @@ forge-dm object-urn my-bucket-key my-object-key
forge-da create-appbundle BundleName path/to/bundle/zipfile Autodesk.Inventor+23 "Bundle description here."

# Updating existing activity
forge-da update-activity ActivityName BundleName BundleAlias Autodesk.Inventor+23 --input PartFile --output Thumbnail:thumbnail.bmp
forge-da update-activity ActivityName BundleName BundleAlias Autodesk.Inventor+23 --input PartFile --output Thumbnail --output-local-name thumbnail.bmp

# Creating work item
forge-da create-workitem ActivityName ActivityAlias --input PartFile:https://some.url --output Thumbnail:https://another.url --short
forge-da create-workitem ActivityName ActivityAlias --input PartFile --input-url https://some.url --output Thumbnail --output-url https://another.url --short
```

> When specifying inputs and outputs for an activity or work item, `--input-*` and `--output-*` arguments
> are always applied to the last input/output ID. For example, consider the following sequence of arguments:
> `--input InputA --input-local-name house.rvt --input InputB --input InputC --input-url https://foobar.com`.
> Such a sequence will define three inputs: _InputA_ with local name _house.rvt_, _InputB_ (with no additional
> properties), and _InputC_ with URL _https://foobar.com_.
#### Model Derivative

```bash
Expand Down
2 changes: 2 additions & 0 deletions examples/inventor-thumbnail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ export FORGE_BUCKET=<your bucket>
```powershell
$env:FORGE_CLIENT_ID = "<your client id>"
$env:FORGE_CLIENT_SECRET = "<your client secret>"
$env:FORGE_BUCKET = "<your bucket>"
.\setup-pipeline.ps1
.\run-pipeline.ps1
```
40 changes: 28 additions & 12 deletions examples/inventor-thumbnail/run-pipeline.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
# FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, and FORGE_BUCKET must be set before running this script.

$forge_dm_bin = "node ..\..\src\forge-dm.js"
$forge_da_bin = "node ..\..\src\forge-da.js"
function Request-DM {
$command = $args[0]
$result = Invoke-Expression "node ..\..\src\forge-dm.js $command"
if ($LASTEXITCODE -ne 0) {
Write-Error "forge-dm command failed: $command" -ErrorAction "Stop"
}
return $result
}

function Request-DA {
$command = $args[0]
$result = Invoke-Expression "node ..\..\src\forge-da.js $command"
if ($LASTEXITCODE -ne 0) {
Write-Error "forge-da command failed: $command" -ErrorAction "Stop"
}
return $result
}

$activity_name = "MyTestActivity"
$activity_alias = "dev"
Expand All @@ -11,36 +26,37 @@ $input_object_key = "input.ipt"
$thumbnail_object_key = "thumbnail.bmp"

# If it does not exist, create a data bucket
$result = Invoke-Expression "$forge_dm_bin list-buckets --short" | Select-String -Pattern $env:FORGE_BUCKET | Measure-Object -Line
$result = Request-DM "list-buckets --short"
$result = $result | Select-String -Pattern $env:FORGE_BUCKET | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating a bucket $env:FORGE_BUCKET"
Invoke-Expression "$forge_dm_bin create-bucket $env:FORGE_BUCKET"
Request-DM "create-bucket $env:FORGE_BUCKET"
}

# Upload Inventor file and create a placeholder for the output thumbnail
Write-Host "Preparing input/output files"
Invoke-Expression "$forge_dm_bin upload-object $input_file_path application/octet-stream $env:FORGE_BUCKET $input_object_key"
Request-DM "upload-object $input_file_path application/octet-stream $env:FORGE_BUCKET $input_object_key"
New-Item -Name "output" -Path "." -ItemType "directory"
New-Item -Name "thumbnail.bmp" -Path ".\output" -ItemType "file"
Invoke-Expression "$forge_dm_bin upload-object .\output\thumbnail.bmp image/bmp $env:FORGE_BUCKET $thumbnail_object_key"
Request-DM "upload-object .\output\thumbnail.bmp image/bmp $env:FORGE_BUCKET $thumbnail_object_key"

# Generate signed URLs for all input and output files
Write-Host "Creating signed URLs"
$input_file_signed_url = Invoke-Expression "$forge_dm_bin create-signed-url $env:FORGE_BUCKET $input_object_key --access read --short"
$thumbnail_signed_url = Invoke-Expression "$forge_dm_bin create-signed-url $env:FORGE_BUCKET $thumbnail_object_key --access readwrite --short"
$input_file_signed_url = Request-DM "create-signed-url $env:FORGE_BUCKET $input_object_key --access read --short"
$thumbnail_signed_url = Request-DM "create-signed-url $env:FORGE_BUCKET $thumbnail_object_key --access readwrite --short"

# Create activity and poll the results
# Create work item and poll the results
Write-Host "Creating work item"
$workitem_id = Invoke-Expression "$forge_da_bin create-workitem $activity_name $activity_alias --input PartFile:$input_file_signed_url --output Thumbnail:$thumbnail_signed_url --short"
$workitem_id = Request-DA "create-workitem $activity_name $activity_alias --input PartFile --input-url $input_file_signed_url --output Thumbnail --output-url $thumbnail_signed_url --short"
Write-Host "Waiting for work item $workitem_id to complete"
$workitem_status = "inprogress"
while ($workitem_status -eq "inprogress") {
Start-Sleep -s 5
$workitem_status = Invoke-Expression "$forge_da_bin get-workitem $workitem_id --short"
$workitem_status = Request-DA "get-workitem $workitem_id --short"
Write-Host $workitem_status
}

# Download the results
Write-Host "Downloading results to output/thumbnail.bmp"
Invoke-Expression "$forge_dm_bin download-object $env:FORGE_BUCKET $thumbnail_object_key output\thumbnail.bmp"
Request-DM "download-object $env:FORGE_BUCKET $thumbnail_object_key output\thumbnail.bmp"
Write-Host "Process complete. See the thumbnail in the output folder, or download it from $thumbnail_signed_url"
6 changes: 4 additions & 2 deletions examples/inventor-thumbnail/run-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, and FORGE_BUCKET must be set before running this script.

set -e # Exit on any error

FORGE_DM_SCRIPT="node ../../src/forge-dm.js"
FORGE_DA_SCRIPT="node ../../src/forge-da.js"

Expand Down Expand Up @@ -31,9 +33,9 @@ echo "Creating signed URLs"
INPUT_FILE_SIGNED_URL=$($FORGE_DM_SCRIPT create-signed-url $FORGE_BUCKET $INPUT_OBJECT_KEY --access read --short)
THUMBNAIL_SIGNED_URL=$($FORGE_DM_SCRIPT create-signed-url $FORGE_BUCKET $THUMBNAIL_OBJECT_KEY --access readwrite --short)

# Create activity and poll the results
# Create work item and poll the results
echo "Creating work item"
WORKITEM_ID=$($FORGE_DA_SCRIPT create-workitem $ACTIVITY_NAME $ACTIVITY_ALIAS --input PartFile:$INPUT_FILE_SIGNED_URL --output Thumbnail:$THUMBNAIL_SIGNED_URL --short)
WORKITEM_ID=$($FORGE_DA_SCRIPT create-workitem $ACTIVITY_NAME $ACTIVITY_ALIAS --input PartFile --input-url $INPUT_FILE_SIGNED_URL --output Thumbnail --output-url $THUMBNAIL_SIGNED_URL --short)
echo "Waiting for work item $WORKITEM_ID to complete"
WORKITEM_STATUS="inprogress"
while [ $WORKITEM_STATUS == "inprogress" ]
Expand Down
43 changes: 28 additions & 15 deletions examples/inventor-thumbnail/setup-pipeline.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, and FORGE_BUCKET must be set before running this script.

$forge_da_bin = "node ..\..\src\forge-da.js"
function Request-DA {
$command = $args[0]
$result = Invoke-Expression "node ..\..\src\forge-da.js $command"
if ($LASTEXITCODE -ne 0) {
Write-Error "forge-da command failed: $command" -ErrorAction "Stop"
}
return $result
}

$appbundle_name = "MyTestBundle"
$appbundle_alias = "dev"
Expand All @@ -12,48 +19,54 @@ $activity_alias = "dev"

# Create or update an appbundle
Write-Host "Creating an appbundle $appbundle_name"
$result = Invoke-Expression "$forge_da_bin list-appbundles --short" | Select-String -Pattern $appbundle_name | Measure-Object -Line
$result = Request-DA "list-appbundles --short"
$result = $result | Select-String -Pattern $appbundle_name | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new appbundle"
Invoke-Expression "$forge_da_bin create-appbundle $appbundle_name $appbundle_file $appbundle_engine"
Request-DA "create-appbundle $appbundle_name $appbundle_file $appbundle_engine"
} else {
Write-Host "Updating existing appbundle"
Invoke-Expression "$forge_da_bin update-appbundle $appbundle_name $appbundle_file $appbundle_engine"
Request-DA "update-appbundle $appbundle_name $appbundle_file $appbundle_engine"
}

# Create or update an appbundle alias
Write-Host "Creating an appbundle alias $appbundle_alias"
$appbundle_version = Invoke-Expression "$forge_da_bin list-appbundle-versions $appbundle_name --short" | Select-Object -Last 1
$result = Request-DA "list-appbundle-versions $appbundle_name --short"
$appbundle_version = $result | Select-Object -Last 1
Write-Host "Last appbundle version: $appbundle_version"
$result = Invoke-Expression "$forge_da_bin list-appbundle-aliases $appbundle_name --short" | Select-String -Pattern $appbundle_alias | Measure-Object -Line
$result = Request-DA "list-appbundle-aliases $appbundle_name --short"
$result = $result | Select-String -Pattern $appbundle_alias | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new appbundle alias"
Invoke-Expression "$forge_da_bin create-appbundle-alias $appbundle_alias $appbundle_name $appbundle_version"
Request-DA "create-appbundle-alias $appbundle_alias $appbundle_name $appbundle_version"
} else {
Write-Host "Updating existing appbundle alias"
Invoke-Expression "$forge_da_bin update-appbundle-alias $appbundle_alias $appbundle_name $appbundle_version"
Request-DA "update-appbundle-alias $appbundle_alias $appbundle_name $appbundle_version"
}

# Create or update an activity
Write-Host "Creating an activity $activity_name"
$result = Invoke-Expression "$forge_da_bin list-activities --short" | Select-String -Pattern $activity_name | Measure-Object -Line
$result = Request-DA "list-activities --short"
$result = $result | Select-String -Pattern $activity_name | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new activity"
Invoke-Expression "$forge_da_bin create-activity $activity_name $appbundle_name $appbundle_alias $appbundle_engine --input PartFile --output Thumbnail:thumbnail.bmp"
Request-DA "create-activity $activity_name $appbundle_name $appbundle_alias $appbundle_engine --input PartFile --output Thumbnail --output-local-name thumbnail.bmp"
} else {
Write-Host "Updating existing activity"
Invoke-Expression "$forge_da_bin update-activity $activity_name $appbundle_name $appbundle_alias $appbundle_engine --input PartFile --output Thumbnail:thumbnail.bmp"
Request-DA "update-activity $activity_name $appbundle_name $appbundle_alias $appbundle_engine --input PartFile --output Thumbnail --output-local-name thumbnail.bmp"
}

# Create or update an activity alias
Write-Host "Creating an activity alias $activity_alias"
$activity_version = Invoke-Expression "$forge_da_bin list-activity-versions $activity_name --short" | Select-Object -Last 1
$result = Request-DA "list-activity-versions $activity_name --short"
$activity_version = $result | Select-Object -Last 1
Write-Host "Last activity version: $activity_version"
$result = Invoke-Expression "$forge_da_bin list-activity-aliases $activity_name --short" | Select-String -Pattern $activity_alias | Measure-Object -Line
$result = Request-DA "list-activity-aliases $activity_name --short"
$result = $result | Select-String -Pattern $activity_alias | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new activity alias"
Invoke-Expression "$forge_da_bin create-activity-alias $activity_alias $activity_name $activity_version"
Request-DA "create-activity-alias $activity_alias $activity_name $activity_version"
} else {
Write-Host "Updating existing activity alias"
Invoke-Expression "$forge_da_bin update-activity-alias $activity_alias $activity_name $activity_version"
Request-DA "update-activity-alias $activity_alias $activity_name $activity_version"
}
6 changes: 4 additions & 2 deletions examples/inventor-thumbnail/setup-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, and FORGE_BUCKET must be set before running this script.

set -e # Exit on any error

FORGE_DA_SCRIPT="node ../../src/forge-da.js"

APPBUNDLE_NAME=TestBundle
Expand Down Expand Up @@ -37,10 +39,10 @@ fi
if [ $($FORGE_DA_SCRIPT list-activities --short | grep $ACTIVITY_NAME | wc -l) -eq "0" ] # TODO: use better matching
then
echo "Creating new activity"
$FORGE_DA_SCRIPT create-activity $ACTIVITY_NAME $APPBUNDLE_NAME $APPBUNDLE_ALIAS $APPBUNDLE_ENGINE --input PartFile --output Thumbnail:thumbnail.bmp
$FORGE_DA_SCRIPT create-activity $ACTIVITY_NAME $APPBUNDLE_NAME $APPBUNDLE_ALIAS $APPBUNDLE_ENGINE --input PartFile --output Thumbnail --output-local-name thumbnail.bmp
else
echo "Updating existing activity"
$FORGE_DA_SCRIPT update-activity $ACTIVITY_NAME $APPBUNDLE_NAME $APPBUNDLE_ALIAS $APPBUNDLE_ENGINE --input PartFile --output Thumbnail:thumbnail.bmp
$FORGE_DA_SCRIPT update-activity $ACTIVITY_NAME $APPBUNDLE_NAME $APPBUNDLE_ALIAS $APPBUNDLE_ENGINE --input PartFile --output Thumbnail --output-local-name thumbnail.bmp
fi

# Create or update an activity alias
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "forge-cli-utils",
"version": "0.7.3",
"version": "0.8.0",
"description": "Command line tools for Autodesk Forge services.",
"author": "Petr Broz <[email protected]>",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function error(err) {
} else {
console.error(err);
}
process.exit(1);
}

module.exports = {
Expand Down
Loading

0 comments on commit 0ac12b3

Please sign in to comment.