Doubt using the REST method: "/v2/resource_match"


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Hi,

I am calling this method: "/v2/resource_match" but I have a doubt with
the server response.

Reading the documentation:
http://apidocs.cloudfoundry.org/214/resource_match/list_all_matching_resources.html

I observe that the response returns a body with content:

[{"sha1":"3722059cc37f7a56db064c1911f063da826cb211","size":36}]

But when I execute the method, I receive a 200 status and but the body
is empty.

Is it normal?

Many thanks in advance.

Juan Antonio


Amit Kumar Gupta
 

Hi Juan Antonio,

You need to make a PUT request to that endpoint, with a JSON payload body
in the request. The documentation isn't very clear about what the request
body should be, and how it relates to the response body. The request
consists of a list of hashes, each with a sha1 and size key. The response
is the subset of that list matching blobs in the CC blobstore. Clients can
use this to optimize not uploading blobs that CC already has in its
blobstore.

Best,
Amit

On Wed, Aug 5, 2015 at 6:35 AM, <bren(a)juanantonio.info> wrote:

Hi,

I am calling this method: "/v2/resource_match" but I have a doubt with the
server response.

Reading the documentation:

http://apidocs.cloudfoundry.org/214/resource_match/list_all_matching_resources.html

I observe that the response returns a body with content:

[{"sha1":"3722059cc37f7a56db064c1911f063da826cb211","size":36}]

But when I execute the method, I receive a 200 status and but the body is
empty.

Is it normal?

Many thanks in advance.

Juan Antonio


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Hi Amit,

to upload an application (A zip), it is mandatory to execute this method?

The method which I am trying to use to upload the application is:
http://apidocs.cloudfoundry.org/214/apps/uploads_the_bits_for_an_app.html

Many thanks for the support.

Juan Antonio


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Hi,

I enabled traces.

```
set CF_TRACE=true
```

The output is empty:

```
Uploading StaticWebsiteHelloWorld...

REQUEST: [2015-08-06T14:11:31+02:00]
PUT /v2/resource_match HTTP/1.1
Host: api.MY_IP.xip.io
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: application/json
User-Agent: go-cli 6.12.1-56792aa / windows

[{"fn":"index.html","sha1":"b657e91776782799aa20eee057603fe03ead4004","size":122},{"fn":"output.txt","sha1":"cc81d5428688235ff1e3cff139a5369d7a817a99","size":12479}]

RESPONSE: [2015-08-06T14:11:31+02:00]
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json;charset=utf-8
Date: Thu, 06 Aug 2015 12:10:03 GMT
Server: nginx
X-Cf-Requestid: 30904f59-005c-4ca1-48a3-2ed46996ba45
X-Content-Type-Options: nosniff
X-Vcap-Request-Id: 8acb0876-9116-473c-6d0a-9939167ada31::69998296-3130-46d6-9f16-ada90aaa309c

[]
Uploading app files from: C:\Users\PATH\StaticWebsite_HelloWorld
Uploading 13.3K, 2 files

REQUEST: [2015-08-06T14:11:31+02:00]
PUT /v2/apps/f7ea4e1b-49a1-4b3f-8c67-eff9574b0a9e/bits?async=true HTTP/1.1
Host: api.MY_IP.xip.io
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: multipart/form-data; boundary=3a1765597317479ad0600360e4a73537c4da9271587bff5a4d6d06089486
User-Agent: go-cli 6.12.1-56792aa / windows


[MULTIPART/FORM-DATA CONTENT HIDDEN]

Done uploading

RESPONSE: [2015-08-06T14:11:31+02:00]
HTTP/1.1 201 Created
Content-Length: 270
Content-Type: application/json;charset=utf-8
Date: Thu, 06 Aug 2015 12:10:04 GMT
Server: nginx
X-Cf-Requestid: 1653aed7-b9a7-41ca-5b50-43bd63b592d9
X-Content-Type-Options: nosniff
X-Vcap-Request-Id: caa69d25-9159-4253-4748-fff9206b41ef::22095047-4e1c-452d-aafa-cce7968094e5

{
"metadata": {
"guid": "7ed54165-8205-4a36-946e-40a55e7636fb",
"created_at": "2015-08-06T12:10:04Z",
"url": "/v2/jobs/7ed54165-8205-4a36-946e-40a55e7636fb"
},
"entity": {
"guid": "7ed54165-8205-4a36-946e-40a55e7636fb",
"status": "queued"
}
}

```

The right format for resources is:

```
[{"fn":"index.html","sha1":"b657e91776782799aa20eee057603fe03ead4004","size":122},{"fn":"output.txt","sha1":"cc81d5428688235ff1e3cff139a5369d7a817a99","size":12479}]

```


arthur halet
 

Hi,

The resource is empty when nothing matching between your local file and the
blobstore.
Actually, you are not oblige to use resource match to send your app it's
just for don't send everything if you can already find file inside the
blobstore.

Le jeudi 6 août 2015, Juan Antonio Breña Moral <bren(a)juanantonio.info> a
écrit :

Hi,

I enabled traces.

```
set CF_TRACE=true
```

The output is empty:

```
Uploading StaticWebsiteHelloWorld...

REQUEST: [2015-08-06T14:11:31+02:00]
PUT /v2/resource_match HTTP/1.1
Host: api.MY_IP.xip.io
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: application/json
User-Agent: go-cli 6.12.1-56792aa / windows


[{"fn":"index.html","sha1":"b657e91776782799aa20eee057603fe03ead4004","size":122},{"fn":"output.txt","sha1":"cc81d5428688235ff1e3cff139a5369d7a817a99","size":12479}]

RESPONSE: [2015-08-06T14:11:31+02:00]
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json;charset=utf-8
Date: Thu, 06 Aug 2015 12:10:03 GMT
Server: nginx
X-Cf-Requestid: 30904f59-005c-4ca1-48a3-2ed46996ba45
X-Content-Type-Options: nosniff
X-Vcap-Request-Id:
8acb0876-9116-473c-6d0a-9939167ada31::69998296-3130-46d6-9f16-ada90aaa309c

[]
Uploading app files from: C:\Users\PATH\StaticWebsite_HelloWorld
Uploading 13.3K, 2 files

REQUEST: [2015-08-06T14:11:31+02:00]
PUT /v2/apps/f7ea4e1b-49a1-4b3f-8c67-eff9574b0a9e/bits?async=true HTTP/1.1
Host: api.MY_IP.xip.io
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: multipart/form-data;
boundary=3a1765597317479ad0600360e4a73537c4da9271587bff5a4d6d06089486
User-Agent: go-cli 6.12.1-56792aa / windows


[MULTIPART/FORM-DATA CONTENT HIDDEN]

Done uploading

RESPONSE: [2015-08-06T14:11:31+02:00]
HTTP/1.1 201 Created
Content-Length: 270
Content-Type: application/json;charset=utf-8
Date: Thu, 06 Aug 2015 12:10:04 GMT
Server: nginx
X-Cf-Requestid: 1653aed7-b9a7-41ca-5b50-43bd63b592d9
X-Content-Type-Options: nosniff
X-Vcap-Request-Id:
caa69d25-9159-4253-4748-fff9206b41ef::22095047-4e1c-452d-aafa-cce7968094e5

{
"metadata": {
"guid": "7ed54165-8205-4a36-946e-40a55e7636fb",
"created_at": "2015-08-06T12:10:04Z",
"url": "/v2/jobs/7ed54165-8205-4a36-946e-40a55e7636fb"
},
"entity": {
"guid": "7ed54165-8205-4a36-946e-40a55e7636fb",
"status": "queued"
}
}

```

The right format for resources is:

```

[{"fn":"index.html","sha1":"b657e91776782799aa20eee057603fe03ead4004","size":122},{"fn":"output.txt","sha1":"cc81d5428688235ff1e3cff139a5369d7a817a99","size":12479}]

```


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Hi Arthur,

My initial idea, is the development of a Node.js client to upload application to CF.
Reading your lines, I understood that It is not necessary to execute the method: /v2/resource_match , is it correct? So, I only would have to execute the method:

'/v2/apps/' + app_guid + '/bits'

Today, I was doing some tests and I am able to upload the estructure, but files are empty. What is the problem with the files? Is it something related with the method: "/v2/resource_match"?

Many thanks in advance.

Note: I think that exist some hours of delay using this mailing list. Github is realtime I mean. :)


Christopher Piraino <cpiraino@...>
 

Juan,

That is correct, you do not need to call /v2/resource_match. I am not sure
what you mean by being able to upload the structure(?) but the files being
empty. If you could clarify that would be helpful.

An important aspect to note about the "/v2/apps/:guid/bits" endpoint is
that it expects a multipart PUT to be sent to it. The API docs here[1]
should help. In your case, the resources block would be an empty array
since you are not using resource matching.

- Chris Piraino

[1]:
http://apidocs.cloudfoundry.org/214/apps/uploads_the_bits_for_an_app.html

On Thu, Aug 6, 2015 at 2:31 PM, Juan Antonio Breña Moral <
bren(a)juanantonio.info> wrote:

Hi Arthur,

My initial idea, is the development of a Node.js client to upload
application to CF.
Reading your lines, I understood that It is not necessary to execute the
method: /v2/resource_match , is it correct? So, I only would have to
execute the method:

'/v2/apps/' + app_guid + '/bits'

Today, I was doing some tests and I am able to upload the estructure, but
files are empty. What is the problem with the files? Is it something
related with the method: "/v2/resource_match"?

Many thanks in advance.

Note: I think that exist some hours of delay using this mailing list.
Github is realtime I mean. :)


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Once, the application is running, I can see the files:

``` shell
cf files StaticWebsiteHelloWorld app
Obteniendo archivos para app StaticWebsiteHelloWorld en org DevBox / space dev como admin...
OK

boot.sh 1.5K
index.html 0B
manifest.yml 0B
nginx/ -
public/ -
````
If I get access to public folder, the files are empty too, but the structure is correct. I suppose that the upload process was correct, isn't it?

Why the files are empty?
How to fix the problem?

``` shell
cf files StaticWebsiteHelloWorld app/public
Obteniendo archivos para app StaticWebsiteHelloWorld en org DevBox / space dev como admin...
OK

index.html 0B
```

Note: I suppose that in public folder, CF remove manifest.yml by security criteria, I mean.

Juan Antonio


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Currently, CC returns "[ ]" for this structure:

[ { fn: 'index.html',
size: 1482,
sha1: '59f1e65c3576dfc0bf839d1822e644644a80c2fb' },
{ fn: 'manifest.yml',
size: 207,
sha1: 'dce3b3949eb4c28c4a01cfdbe614e6de16d204bb' } ]
[]

If I send the response: [] in the method upload:
http://apidocs.cloudfoundry.org/214/apps/uploads_the_bits_for_an_app.html

I receive this answer:

400
{ code: 160001,
description: 'The app upload is invalid: invalid :resources',
error_code: 'CF-AppBitsUploadInvalid' }

What is right format for [] if CC returns this value?

In node, I make this request:

request({
method:'PUT',
uri: url,
auth:{bearer:access_token},
formData:{
async:'true',
resources: JSON.stringify("[]"), <-- QUESTION
application:fs.createReadStream("./StaticWebsite_HelloWorld.zip")
},
json:true
}

Many thanks in advance.

Juan Antonio


Juan Antonio Breña Moral <bren at juanantonio.info...>
 


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Hi Chris, Arthur & Amit,

Today, I continued with the tests and checking and observing CLI.

CLI when it checks that the app doesn't exist, execute the method: /v2/resource_match

Uploading StaticWebsiteHelloWorld...

REQUEST: [2015-08-07T11:47:15+02:00]
PUT /v2/resource_match HTTP/1.1
Host: api.MY_API.xip.io
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: application/json
User-Agent: go-cli 6.12.1-56792aa / windows

[{"fn":"StaticWebsite_HelloWorld.zip","sha1":"63329d8506a84fe7d94b8104d1ea073065bc5ff1","size":615},{"fn":"index.html","sha1":"6d94e23263b6e29c5ad1db4d11cca92889d8cd77","size":250},{"fn":"outputAdd.txt","sha1":"b702563871feed5f502ca8f85d30d3b58e8c9012","size":12474}]

RESPONSE: [2015-08-07T11:47:16+02:00]
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json;charset=utf-8
Date: Fri, 07 Aug 2015 09:45:45 GMT
Server: nginx
X-Cf-Requestid: 1a6a2edf-4662-4232-5c8a-e03908ab9ba4
X-Content-Type-Options: nosniff
X-Vcap-Request-Id: 4aae4900-5cb2-4ff7-5655-ddc289585577::c9de547e-e726-4f87-9c19-12979089ca16

[]

and returns an empty array.

When CLI update an application, it does the same thing:

Uploading StaticWebsiteHelloWorld...

REQUEST: [2015-08-07T11:47:49+02:00]
PUT /v2/resource_match HTTP/1.1
Host: api.MY_API.xip.io
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: application/json
User-Agent: go-cli 6.12.1-56792aa / windows

[{"fn":"StaticWebsite_HelloWorld.zip","sha1":"63329d8506a84fe7d94b8104d1ea073065bc5ff1","size":615},{"fn":"index.html","sha1":"6d94e23263b6e29c5ad1db4d11cca92889d8cd77","size":250},{"fn":"outputAdd.txt","sha1":"31d74639918621e74b4ba106d1e60db4bdae2353","size":39602},{"fn":"outputUpdate.txt","sha1":"93dfd14a8c2c46cef0cde0fb1b423153174a5cd2","size":18963}]

RESPONSE: [2015-08-07T11:47:49+02:00]
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json;charset=utf-8
Date: Fri, 07 Aug 2015 09:46:19 GMT
Server: nginx
X-Cf-Requestid: df233fed-f221-4123-70a5-5ef4be342fd6
X-Content-Type-Options: nosniff
X-Vcap-Request-Id: 784047bd-4b34-4658-6618-a82157ba4279::d5b05c14-02ac-4f65-bc0c-64a3e272b89f

[]

Currently, I am executing the method, but I receive the following message:

{ metadata:
{ guid: '1e7e956e-4784-42c7-a82c-b56fac823a5f',
created_at: '2015-08-07T10:12:02Z',
url: '/v2/jobs/1e7e956e-4784-42c7-a82c-b56fac823a5f' },
entity:
{ guid: '1e7e956e-4784-42c7-a82c-b56fac823a5f',
status: 'failed',
error: 'Use of entity>error is deprecated in favor of entity>error_details.',
error_details:
{ code: 160001,
description: 'The app upload is invalid: invalid :resources',
error_code: 'CF-AppBitsUploadInvalid' } } }

Error: {
"code": 150001,
"description": "The app package is invalid: bits have not been uploaded",
"error_code": "CF-AppPackageInvalid"
}

Does exist a curl way to upload an application?
In the documentation, I don't see anything.

http://apidocs.cloudfoundry.org/214/apps/uploads_the_bits_for_an_app.html

Besides, If you observe, the docs show that it is necessary to add the details:

Content-Disposition: form-data; name="resources"

[{"fn":"path/to/content.txt","size":123,"sha1":"b907173290db6a155949ab4dc9b2d019dea0c901"},{"fn":"path/to/code.jar","size":123,"sha1":"ff84f89760317996b9dd180ab996b079f418396f"}]

But it is a bit rare, because in another reply, you said that it is not necessary, because the method only need the response about the method:

/v2/resource_match

Doubts:
What is the right input for the field resources if the method: "/v2/resource_match" returns []
Does exist a curl command to upload an application?

Many thanks in advance

Juan Antonio


Amit Kumar Gupta
 

Instead of

JSON.stringify("[]")

I think you just want

[]

As to your files being empty, the docs mention that you need to do a
multipart upload PUT request, and include a zip file called "application".
Can you verify that your PUT request looks correct, and the contents of
your application zip look correct?

On Thu, Aug 6, 2015 at 3:46 PM, Juan Antonio Breña Moral <
bren(a)juanantonio.info> wrote:


https://github.com/jabrena/cf-nodejs-client/blob/master/lib/model/Apps.js#L301-L340


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Finally,

I fixed the problem.
I deployed my first HelloWorld from Node.

-----> Downloaded app package (4.0K)

cf files StaticWebsiteHelloWorld app/public
Obteniendo archivos para app StaticWebsiteHelloWorld en org DevBox / space dev como admin...
OK
index.html 1.4K

Next week, I will try to refactor and clean the code to continue with the tests.
Many thanks for the support

Nice weekend.

Cheers

Juan Antonio


Amit Kumar Gupta
 

Juan Antonio,

When you say "Currently, I am executing the method, but I receive the
following message:", what "method" are you executing? The error message
suggests that the "resources" param you're providing in your request body
(whatever your request may be) is invalid. In a previous email, you
mentioned you were setting the value to JSON.stringify("[]") which I
pointed out as incorrect. Did you fix that?

In response to "But it is a bit rare, because in another reply, you said
that it is not necessary", the docs say that for the "uploading bits"
endpoint you need to provide the "resources" data. In the previous email,
someone mentioned that you don't need to call the "resource_match" endpoint
first. These two facts are not contradictory. If I understand correctly,
you should always be able to just set "resources" to an empty array, the
"resources" data is just an optimization to prevent it from uploading all
the files if some have already been uploaded. Since you're still just
trying to get it to work, I would not worry about this optimization for now.

You only need to call the resources_match endpoint to figure out the
correct value to enter in the resources parameter in the app-bits-upload
request *if* you want to take advantage of the optimization of not
uploading already-uploaded bits. You should not worry about this
optimization for now.

For the uploading bits endpoint, you also need to include a file to upload
along with your curl command. Uploading a file with curl is different from
setting the body of the request. If you're using curl or some JavaScript
library to try to make requests, please research how to upload files as I
know it can be a little bit finicky. I can't recall the exact syntax to do
it using curl, but I do remember it being a bit weird.

Amit

On Fri, Aug 7, 2015 at 3:54 AM, Juan Antonio Breña Moral <
bren(a)juanantonio.info> wrote:

Hi Chris, Arthur & Amit,

Today, I continued with the tests and checking and observing CLI.

CLI when it checks that the app doesn't exist, execute the method:
/v2/resource_match

Uploading StaticWebsiteHelloWorld...

REQUEST: [2015-08-07T11:47:15+02:00]
PUT /v2/resource_match HTTP/1.1
Host: api.MY_API.xip.io
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: application/json
User-Agent: go-cli 6.12.1-56792aa / windows


[{"fn":"StaticWebsite_HelloWorld.zip","sha1":"63329d8506a84fe7d94b8104d1ea073065bc5ff1","size":615},{"fn":"index.html","sha1":"6d94e23263b6e29c5ad1db4d11cca92889d8cd77","size":250},{"fn":"outputAdd.txt","sha1":"b702563871feed5f502ca8f85d30d3b58e8c9012","size":12474}]

RESPONSE: [2015-08-07T11:47:16+02:00]
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json;charset=utf-8
Date: Fri, 07 Aug 2015 09:45:45 GMT
Server: nginx
X-Cf-Requestid: 1a6a2edf-4662-4232-5c8a-e03908ab9ba4
X-Content-Type-Options: nosniff
X-Vcap-Request-Id:
4aae4900-5cb2-4ff7-5655-ddc289585577::c9de547e-e726-4f87-9c19-12979089ca16

[]

and returns an empty array.

When CLI update an application, it does the same thing:

Uploading StaticWebsiteHelloWorld...

REQUEST: [2015-08-07T11:47:49+02:00]
PUT /v2/resource_match HTTP/1.1
Host: api.MY_API.xip.io
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: application/json
User-Agent: go-cli 6.12.1-56792aa / windows


[{"fn":"StaticWebsite_HelloWorld.zip","sha1":"63329d8506a84fe7d94b8104d1ea073065bc5ff1","size":615},{"fn":"index.html","sha1":"6d94e23263b6e29c5ad1db4d11cca92889d8cd77","size":250},{"fn":"outputAdd.txt","sha1":"31d74639918621e74b4ba106d1e60db4bdae2353","size":39602},{"fn":"outputUpdate.txt","sha1":"93dfd14a8c2c46cef0cde0fb1b423153174a5cd2","size":18963}]

RESPONSE: [2015-08-07T11:47:49+02:00]
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json;charset=utf-8
Date: Fri, 07 Aug 2015 09:46:19 GMT
Server: nginx
X-Cf-Requestid: df233fed-f221-4123-70a5-5ef4be342fd6
X-Content-Type-Options: nosniff
X-Vcap-Request-Id:
784047bd-4b34-4658-6618-a82157ba4279::d5b05c14-02ac-4f65-bc0c-64a3e272b89f

[]

Currently, I am executing the method, but I receive the following message:

{ metadata:
{ guid: '1e7e956e-4784-42c7-a82c-b56fac823a5f',
created_at: '2015-08-07T10:12:02Z',
url: '/v2/jobs/1e7e956e-4784-42c7-a82c-b56fac823a5f' },
entity:
{ guid: '1e7e956e-4784-42c7-a82c-b56fac823a5f',
status: 'failed',
error: 'Use of entity>error is deprecated in favor of
entity>error_details.',
error_details:
{ code: 160001,
description: 'The app upload is invalid: invalid :resources',
error_code: 'CF-AppBitsUploadInvalid' } } }

Error: {
"code": 150001,
"description": "The app package is invalid: bits have not been uploaded",
"error_code": "CF-AppPackageInvalid"
}

Does exist a curl way to upload an application?
In the documentation, I don't see anything.

http://apidocs.cloudfoundry.org/214/apps/uploads_the_bits_for_an_app.html

Besides, If you observe, the docs show that it is necessary to add the
details:

Content-Disposition: form-data; name="resources"


[{"fn":"path/to/content.txt","size":123,"sha1":"b907173290db6a155949ab4dc9b2d019dea0c901"},{"fn":"path/to/code.jar","size":123,"sha1":"ff84f89760317996b9dd180ab996b079f418396f"}]

But it is a bit rare, because in another reply, you said that it is not
necessary, because the method only need the response about the method:

/v2/resource_match

Doubts:
What is the right input for the field resources if the method:
"/v2/resource_match" returns []
Does exist a curl command to upload an application?

Many thanks in advance

Juan Antonio


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Hi Amit,

yes, I do a PUT Multipart, uploading the application in a zip.

This week, I will do some stress test for this method.
https://github.com/jabrena/cf-nodejs-client/blob/master/lib/model/Apps.js#L289-L312