VMware Cloud Community
clabman
Contributor
Contributor
Jump to solution

Import a Workflow with Orchestrator Rest API

Hi,

I'm trying to import a workflow to Orchestrator through the REST API, but it always end up with an error 500 :

HTTP/1.1 100 Continue
HTTP/1.1 500 Internal Server Error
Content-Type: text/html;charset=utf-8
Transfer-Encoding: chunked
Date: Thu, 28 Feb 2013 16:54:57 GMT
Connection: close
Server: vCO Server
I proceed this way :
I prepare the file that will be send :

------------------------------5bf10fbcf09

Content-Disposition: form-data; name="listVm"; filename="listVm.workflow"

Content-Type: application/zip

Binary

------------------------------5bf10fbcf09--

and then make a POST request to my vCO server :
curl -ik -u "user:pass" -H "Accept:application/xml" -H "Content-type:multipart/form-data; boundary=------------------------------5bf10fbcf09" -H "Content-length:19442" https://IP:PORT/api/workflows/ -X POST -d @listVm.wf
Then it's going in pending state :
HTTP/1.1 100 Continue
and about 60s later it returns me an error 500
Thanks for your help !!

0 Kudos
1 Solution

Accepted Solutions
ivand
VMware Employee
VMware Employee
Jump to solution

Here is a code that imports a workflow under a category:

     VcoSessionFactory sessionFactory = new DefaultVcoSessionFactory(new URI("https://vcohost:8281/api")) {
            @Override
            protected SSLContext newSSLContext() throws KeyManagementException, NoSuchAlgorithmException {
                return newUnsecureSSLContext();
            }
            @Override
            protected HostnameVerifier newHostnameVerifier() {
                return newUnsecureHostnameVerifier();
            }
        };
        // This is for basic authentication in when vCO is in LDAP mode
        Authentication authentication = new UsernamePasswordAuthentication("userName", "password");
        // This is for SSO authentication
        // Authentication authentication = null;
        // try {
        // SsoAuthenticator authenticator =
        // new SsoAuthenticator(new
        // URI("https://ssoHost:ssoPort/ims/STSService?wsdl"), sessionFactory,
        // 1800l);
        // authentication =
        // authenticator.createSsoAuthentication("userName",
        // "password");
        // } catch (IOException e) {
        // throw new RuntimeException("unable to authenticate to SSO", e);
        // } catch (URISyntaxException e) {
        // // Unlikely to happen
        // }
        VcoSession session = sessionFactory.newSession(authentication);
        WorkflowService wfService = new WorkflowService(session);
        wfService.importWorkflowInCategory("categoryId", new File(
                "path_to_some_workflow.workflow"));

I this code I am using only the Rest client that is provided with vCO:

https://vcohost:8281/api/docs/downloads.html

Hope this helps

Regards

Ivan

View solution in original post

0 Kudos
14 Replies
ivand
VMware Employee
VMware Employee
Jump to solution

Your REST end point  should be:

https://IP:PORT/api/content/workflows/<workflowcategory_path>

where <workflowcategory_path> is teh path to the category where you want to import the workflow

please, try it this

Regards

Ivan

0 Kudos
clabman
Contributor
Contributor
Jump to solution

Hi Ivand,

Thanks for your help.

I've just tried your advice :

https://IP:PORT/api/content/workflows/Library/Orchestrator/Workflows

But still the same error.... It seems that vCO can't read my binary... "error 500, read timeout"

0 Kudos
ivand
VMware Employee
VMware Employee
Jump to solution

Can you attached vCO server log? It is located in <vco_install_folder>/app-server/server/vmo/logs

I need to see what error is thrown

Regards

Ivan

0 Kudos
clabman
Contributor
Contributor
Jump to solution

Yes for sur, here is the server.log with the error thrown by the server when I tried to import a workflow !

Thanks for your help !

0 Kudos
ivand
VMware Employee
VMware Employee
Jump to solution

Well, I made a mistake Smiley Sad

You should post to https://vco:port/content/workflows/{categoryId}

where categoryId is the id of the category where you want to import the workflow

Look here in REST API docs: https://vco:port/api/docs/resource_Content%20Service.html#.content.workflows.-categoryId-

This category id can be get using GET to https://vco:port/api/categories and look for target category ID

Look here in REST API docs: https://10.23.33.55:8281/api/docs/resource_Category%20Service.html#.categories

Hope this helps

Ivan

0 Kudos
clabman
Contributor
Contributor
Jump to solution

Thanks for your quick answer Smiley Happy

Same problem with the category....

But on documentations I've seen that you can Post this kind of request to this url : https://IP:PORT/api/workflows

https://IP:PORT/api/docs/resource_Workflow%20Service.html#.workflows

So it should work...

And in logs, the read timeout error makes me think to read problem of my binary...

0 Kudos
clabman
Contributor
Contributor
Jump to solution

Just to verify....

The request must be sent to port 8281 or 8244 ?

Thanks for your help !

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

The request should be sent to the SSL port, the default for this is 8281.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
clabman
Contributor
Contributor
Jump to solution

Ok so, I'm right on this point :

curl -i -S -k --fail -v -u "admin:pass" https://IP:8281/api/workflows -H "Content-length:19098" -F "file=@listVm.workflow"

But it still returns :

> POST /api/workflows HTTP/1.1

> Authorization: Basic Ywefklnfjkonlfe=

> User-Agent: curl/7.27.0

> Host: IP:8281

> Accept: */*

> Content-length:19098

> Expect: 100-continue

> Content-Type: multipart/form-data; boundary=----------------------------0d35baebabcc

>

* additional stuff not fine transfer.c:1037: 0 0

* HTTP 1.1 or later with persistent connection, pipelining supported

< HTTP/1.1 100 Continue

HTTP/1.1 100 Continue

* additional stuff not fine transfer.c:1037: 0 0

* additional stuff not fine transfer.c:1037: 0 0

* additional stuff not fine transfer.c:1037: 0 0

* additional stuff not fine transfer.c:1037: 0 0

* additional stuff not fine transfer.c:1037: 0 0

* The requested URL returned error: 500 Internal Server Error

* Closing connection #0

curl: (22) The requested URL returned error: 500 Internal Server Error

* SSL read: error:00000000:lib(0):func(0):reason(0), errno 104

0 Kudos
ivand
VMware Employee
VMware Employee
Jump to solution

Here is a code that imports a workflow under a category:

     VcoSessionFactory sessionFactory = new DefaultVcoSessionFactory(new URI("https://vcohost:8281/api")) {
            @Override
            protected SSLContext newSSLContext() throws KeyManagementException, NoSuchAlgorithmException {
                return newUnsecureSSLContext();
            }
            @Override
            protected HostnameVerifier newHostnameVerifier() {
                return newUnsecureHostnameVerifier();
            }
        };
        // This is for basic authentication in when vCO is in LDAP mode
        Authentication authentication = new UsernamePasswordAuthentication("userName", "password");
        // This is for SSO authentication
        // Authentication authentication = null;
        // try {
        // SsoAuthenticator authenticator =
        // new SsoAuthenticator(new
        // URI("https://ssoHost:ssoPort/ims/STSService?wsdl"), sessionFactory,
        // 1800l);
        // authentication =
        // authenticator.createSsoAuthentication("userName",
        // "password");
        // } catch (IOException e) {
        // throw new RuntimeException("unable to authenticate to SSO", e);
        // } catch (URISyntaxException e) {
        // // Unlikely to happen
        // }
        VcoSession session = sessionFactory.newSession(authentication);
        WorkflowService wfService = new WorkflowService(session);
        wfService.importWorkflowInCategory("categoryId", new File(
                "path_to_some_workflow.workflow"));

I this code I am using only the Rest client that is provided with vCO:

https://vcohost:8281/api/docs/downloads.html

Hope this helps

Regards

Ivan

0 Kudos
clabman
Contributor
Contributor
Jump to solution

Ok thanks for these tips !! It works....:)

But if you heard about some tips for vCO Rest API Smiley Happy Do not hesitate to up this topic !

Thanks again.

0 Kudos
bserratrice
VMware Employee
VMware Employee
Jump to solution

Hi clabman,

I successfully uploaded a workflow using the following content directly using HTTP POST request :

--e19b31b9-273b-4b34-b36b-5c59e1dcf326
Content-Disposition: form-data; name="file"; filename="mywf.workflow"
Content-Type: application/zip

<binary data>

--e19b31b9-273b-4b34-b36b-5c59e1dcf326
Content-Disposition: form-data; name="categoryId"

ff808081430be14fff436caace2b1742
--e19b31b9-273b-4b34-b36b-5c59e1dcf326
Content-Disposition: form-data; name="overwrite"

true
--e19b31b9-273b-4b34-b36b-5c59e1dcf326--

Be careful, if you don't have the empty line after Content-Disposition or Content-Type line, it doesn't work.

I hope it helps.

0 Kudos
anuragvr
Enthusiast
Enthusiast
Jump to solution

How you convert workflow file into binary data like -e19b31b9-273b-4b34-b36b-5c59e1dcf326

0 Kudos
bserratrice
VMware Employee
VMware Employee
Jump to solution

You need to use a file reader to convert your file content to string and insert it at the right place in the multipart "syntax" (RFC-2387).