TVM-IO parameters

Use ap.new_io to create IO-cell

ap.new_io('JSON with IO-resource parameters', url)

Types of IO-resources:

AcapellaDB

IO-resource that maps to Acapella DB key image in the keyspace temp of user foo:

-- LUA
local tvm_cell_id = ap.new_io("{'command':'kv'}", 'http://api.acapella.ru:5678/acapelladb/v2/kv/keys/foo:temp:image?&n=3&r=2&w=2')
  • This will only work for the user foo and for users who have access to keyspace temp.
  • All operations with key image will use the following replication settings (NRW): N=3, R=2, W=2.

The NRW parameters can also be specified in the IO-parameters section:

# Python
tvm_cell_id = ap.new_io("{'command':'kv', 'n':3, 'r':2, 'w':2}", 'http://api.acapella.ru:5678/acapelladb/v2/kv/keys/foo:temp:image')

Swift API - cloud FS

-- LUA
local tvm_cell_id = ap.new_io('{"command": "restswift", "headers": { "X-Auth-Token": <token string> }}'  , '<object url>')
  • <object url> must be a cloud url of file.
  • <token string> - authorization token. DO NOT KEEP your passwords, financial, and other personal information in fragment source! This kind of data must be transmitted from outside of the fragment, for example via the transaction arguments or IO-request.

HTTP/REST

WARNING

This type of IO can make side effects in the outside world *immediately* (before invocation of `commit`).

Parameters

-- LUA
local tvm_cell_id = ap.new_io([[{
     command = 'rest'
     method = 'POST'
     headers = 'h1\nh2\n' 
     d = "data"
     T = false
}]]  , '')
  1. IO-parameters:
    • method - HTTP method (GET/POST/DELETE etc). Optional. If the parameter is not specified, then GET is used for reads and POST for writes.
    • headers - HTTP headers, separted with \n sequence.
    • d - HTTP body. Optional.
    • T: true HTTP Body flag. Optional. This means that TVM-cell value is body
  2. Parameter url can be null or empty.

TODO: странная комбинаторика параметров d и T

Example

Example :

function restcurl(url,param2)

end

function gettoken() -- dirty hack , ONLY FOR DEMO
    local cell = ap.new_io([[{
       command='rest'
       headers='X-Auth-User:user\nX-Auth-Key:password\n',
       T=false,
       method='GET',
    }]], 'https://auth.selcdn.ru/' )
    local resp = ap.tvm_get(cell) -- !!! perform GET request throw IO service NOW
    local token = re.match('X-Auth-Token: (.*)$', resp)
    return token
end

Desription

Using this method you can make HTTP-requests at execution moment, but not in commit phase.

  • ap.tvm_get for IO-cell performed immediatly.
  • work can not be rollback-ed.
  • some data can be IO not in start and not in commit phase - danger (TODO нихрена не понел)
  • if fragment was restarted, the changes to the IO-resource will not be "reverted"

This method can be used for work with some immutable data, when programmer understand side effects and there is no danger for app.

d (data) & T params

optional parameters :

  • [ d : "data" ] - body for request
  • [ T : true ] - means that writed value will be a body in request

if params missing for body used data from tvm arg.

if need send POST or PUT req WITH BODY , but ap.tvm_get has not value argument then user can use parameters d and T

T can be used with ap.tvm_set(cell_id, DATA) where DATA used when T==true as request body.

Info

  • ap.tvm_get - work immedialy , has no data value param
  • ap.tvm_set - work in io sequence in commit phase , at the end of transaction (ap.io_commit()), has data value param

Local FS (only for Box , not in Paas)

-- LUA
local tvm_cell_id = ap.new_io("", '/path/path/path/path')

First param must be empty for work with Local fs