{
	"name": "FireIde.Web.Deploy.VCAP.UpdateApp",
	"Web.Endpoint": "POST /deploy/vcap/apps/:app/update",
	"Web.Response.Protocol": "Web.Protocols.Template",
	"json": {
		"@scopeSet(endPoint)": {
			"@get(express.req.body.endpoint)": null
		},
		"@scopeSet(appName)": {
			"@get(express.req.params.app)": null
		},
		"@scopeSet(apiToken)": {
			"@FireIde.Core.VCAP.GetEndpointToken": {
				"@get(endPoint)": null
			}
		},
		"@if(apiToken)": {
			"@scopeSet(appManifest)": {
				"@FireIde.Core.Messaging.Emit(deployment_progress)": {
					"name": "ignitionLoading",
					"type": "status",
					"status": "waiting",
					"message": "Loading Ignition Manifest"
				},
				"@FireIde.Core.AppManifest": null,
				" @FireIde.Core.Messaging.Emit(deployment_progress)": {
					"name": "ignitionLoading",
					"type": "status",
					"status": "success",
					"message": "Loading Ignition Manifest"
				}
			},
			"@if(appManifest)": {
				"@scopeSet(vcapManifest)": {
					"@FireIde.Core.Messaging.Emit(deployment_progress)": {
						"name": "vcapLoading",
						"type": "status",
						"status": "waiting",
						"message": "Loading Application Manifest"
					},
					"@VCAP.Apps.Information": {

						"endpoint": {
							"@get(endPoint)": null
						},
						"token": {
							"@get(apiToken)": null
						},
						"name": {
							"@get(appName)": null
						}
					},
					" @FireIde.Core.Messaging.Emit(deployment_progress)": {
						"name": "vcapLoading",
						"type": "status",
						"status": "success",
						"message": "Loading Application Manifest"
					}
				},
				"@scopeSet(systemServices)": {
					"@FireIde.Core.Messaging.Emit(deployment_progress)": {
						"name": "fetchingSysServices",
						"type": "status",
						"status": "waiting",
						"message": "Fetching System Services"
					},
					"@VCAP.Services.System": {

						"endpoint": {
							"@get(endPoint)": null
						},
						"token": {
							"@get(apiToken)": null
						}
					},
					" @FireIde.Core.Messaging.Emit(deployment_progress)": {
						"name": "fetchingSysServices",
						"type": "status",
						"status": "success",
						"message": "Fetching System Services"
					}
				},
				"@FireIde.Core.VCAP.FilterMissingServices": {
					"appManifest": {
						"@get(appManifest)": null
					},
					"vcapManifest": {
						"@get(vcapManifest)": null
					}
				},
				"@each": {
					"@scopeSet(servicesDescriptions)": {
						"@index(systemServices)": {
							"@get(CurrentItem.serviceType)": null
						}
					},
					"@scopeSet(serviceDescription)": {
						"@index(servicesDescriptions)": {
							"@get(CurrentItem.serviceName)": null
						}
					},
					"@scopeSet(serviceVersion)": {
						"@scopeSet(versions)": {
							"@Commons.Object.Keys(serviceDescription)": null
						},
						"@return": {
							"@index(versions)": 0
						}
					},
					"@scopeSet(serviceDetails)": {
						"@index(serviceDescription)": {
							"@get(serviceVersion)": null
						}
					},
					"@return": {
						"name": {
							"@get(CurrentItem.instanceName)": null
						},
						"vendor": {
							"@get(serviceDetails.vendor)": null
						},
						"tier": "free",
						"version": {
							"@get(serviceVersion)": null
						},
						"type": {
							"@get(CurrentItem.serviceType)": null
						}
					}
				},
				" @each": {
					"@FireIde.Core.Messaging.Emit(deployment_progress)": {
						"name": {
							"@concat": [
								"provisioningService",
								{
									"@get(CurrentItem.name)": null
								}
							]
						},
						"type": "status",
						"status": "waiting",
						"message": {
							"@concat": [
								"Provisioning Service ",
								{
									"@get(CurrentItem.name)": null
								}
							]
						}
					},
					"@VCAP.Services.Provision": {
						"endpoint":{
							"@get(endPoint)": null
						},
						"token": {
							"@get(apiToken)": null
						},
						"info": {
							"@get(CurrentItem)": null
						}
					},
					" @FireIde.Core.Messaging.Emit(deployment_progress)": {
						"name": {
							"@concat": [
								"provisioningService",
								{
									"@get(CurrentItem.name)": null
								}
							]
						},
						"type": "status",
						"status": "waiting",
						"message": {
							"@concat": [
								"Binding Service ",
								{
									"@get(CurrentItem.name)": null
								}
							]
						}
					},
					"@VCAP.Apps.BindService": {
						"endpoint":{
							"@get(endPoint)": null
						},
						"token": {
							"@get(apiToken)": null
						},
						"appName": {
							"@get(appName)": null
						},
						"serviceName": {
							"@get(CurrentItem.name)": null
						}
					},
					"  @FireIde.Core.Messaging.Emit(deployment_progress)": {
						"name": {
							"@concat": [
								"provisioningService",
								{
									"@get(CurrentItem.name)": null
								}
							]
						},
						"type": "status",
						"status": "success",
						"message": {
							"@concat": [
								"Service ",
								{
									"@get(CurrentItem.name)": null
								},
								"(",
								{
									"@get(CurrentItem.vendor)": null
								},
								")",
								" has been provisioned and binded"
							]
						}
					}
				},
				"@FireIde.Core.Messaging.Emit(deployment_progress)": {
					"name": "upload",
					"type": "status",
					"status": "waiting",
					"message": "Uploading"
				},
				"@VCAP.Apps.UpdateSources": {
					"endpoint":{
						"@get(endPoint)": null
					},
					"token": {
						"@get(apiToken)": null
					},
					"appName": {
						"@get(appName)": null
					},
					"dir": "."
				},
				" @FireIde.Core.Messaging.Emit(deployment_progress)": {
					"name": "upload",
					"type": "status",
					"status": "success",
					"message": "Uploaded"
				},
				"  @FireIde.Core.Messaging.Emit(deployment_progress)": {
					"name": "restarting",
					"type": "status",
					"status": "waiting",
					"message": "Restarting"
				},
				"@VCAP.Apps.Stop": {
					"endpoint":{
						"@get(endPoint)": null
					},
					"token": {
						"@get(apiToken)": null
					},
					"appName": {
						"@get(appName)": null
					}
				},
				"@VCAP.Apps.Start": {
					"endpoint":{
						"@get(endPoint)": null
					},
					"token": {
						"@get(apiToken)": null
					},
					"appName": {
						"@get(appName)": null
					}
				},
				"   @FireIde.Core.Messaging.Emit(deployment_progress)": {
					"name": "restarting",
					"type": "status",
					"status": "success",
					"message": "Restarted"
				},
				"@Web.Templates.Render(deploy/vcap/result)": {
					"layout":false,
					"locals": {

					}
				}
			},
			"@unless(appManifest)": {
				"@Web.Response.Status": 201,
				"@Web.Response.Send": "Please fix your application errors first"
			}
		},
		"@unless(apiToken)": {
			"@Web.Response.Status": 403,
			"@Web.Response.Send": "VCAP: Unauthorized"
		}

	}
}