Post

4 followers Follow
0
Avatar

Get the udm.DeployedApplication for an environment using the REST API?

I need to handle updates in my control task script. I was wondering if you knew of a way to get the udm.DeployedApplication from and environment using the rest api? So when my script runs I would like to check if it is an update or an initial, and if its an update I need to pass the udm.DeployedApplication to get to the targeted containers. Make sense?

Any ideas?

Thanks as always!

Bernie Bonn

Please sign in to leave a comment.

11 comments

0
Avatar

Hi Bernie

Regarding your immediate question:

> I was wondering if you knew of a way to get the udm.DeployedApplication from and environment using the rest api?

If you're OK with handling a 404 if the CI doesn't exist, a call to GET /repository/ci/{ID:.*?} (e.g. GET /repository/ci/Environments/MyEnvs/TestEnv/PetClinic) should do the trick. If you want to avoid the 404, an prior call to GET /deployment/exists, passing the application and environment as query parameters (e.g. GET /deployment/exists?application=Applications/MyApps/PetClinic&environment=Environments/MyEnvs/TestEnv) should help.

To take a step back for a moment, though:

> So when my script runs I would like to check if it is an update or an initial, and if its an update I need to pass the udm.DeployedApplication to get to the targeted containers.

Could you briefly describe what you need the targeted containers for? The DeploymentService API endpoint has a number of calls such as POST /deployment/prepare/deployeds and POST /deployment/generate/all that will auto-generate deployeds for you, i.e. without you having to know exactly which containers are in the target environment. I assume none of these work for you?

Regards

Andrew

Andrew Phillips 0 votes
0
Avatar

Hi Andrew,

Thanks for that.  You helped me think of it in a different way.  I do know the application I just have to grab what the user inputs which will be a composite package most likely and strip it back to the application, and I have seen the exists method.   That should work. I was thinking I would get the environment, then look for the currently deployed applications.

Not sure if I am missing what you are asking in the second part, but I need the targeted containers/ hosts because I want to run control tasks against them as a pre deploy check.  Check connection for example.  I am already using the  /deployment/prepare/ to get the deployment object then I map and grab all the hosts for that particular deployment plan.  Does that make sense, maybe I am missing an easier way to do it.   

Bernie Bonn 0 votes
0
Avatar

but I need the targeted containers/ hosts because I want to run control tasks against them as a pre deploy check

Based on the discussion in the XL Release thread, that's what I was guessing. And I assume you want to get the DeployedApplication rather than the Environment because potentially not all hosts in the environment will be targeted?

If you find that most of the containers in an environment are targeted most of the time, it may be easier to simply GET the udm.Environment and loop through its members, than to loop through all the deployed items in a udm.DeployedApplication and extract the actual hosts from those.

Just a thought ;-)

Regards

Andrew

Andrew Phillips 0 votes
0
Avatar

Hi Andrew,

Yes you have it.   I was thinking about looping through the whole environment, but we have many hosts that would be un-targeted, so we thought this would be cleaner.   I think I am on my way, I do an api call to the composite package which as a reference to the application, I can then do an exists and make my decision whether it is an update or initial.   Thanks a lot, I think it might actually work.   

Thanks!

Bernie Bonn 0 votes
0
Avatar

> Thanks a lot, I think it might actually work.

Glad to hear. Looking forward to finding out if it works out!

Regards

Andrew

Andrew Phillips 0 votes
0
Avatar

Rats,

I am still missing something :)   I need to build this url somehow:

deployment/prepare/update/?environment=Environments/EBA/EBA&version=Applications/png/sso/png_sso/png_oct&deployedApplication=Environments/EBA/EBA/png_sso.

I know the environment and the version (comp package) but I don't have the deployedApplication.   Have any nifty ideas?   I was thinking I could maybe parse out the app and add it to the environment someway, but seems hacky.  

Thanks for any insight!

Bernie

 

Bernie Bonn 0 votes
0
Avatar

> I know the environment and the version (comp package) but I don't have the deployedApplication

The default for the ID of the deployed application is <environment-id>/<name-of-application>, so e.g. if the environment is Environments/MyEnvs/Test and the name of the udm.Application (i.e. everything after the last '/' in the ID) is PetClinic, the ID of the deployed application would usually be Enviornments/MyEnvs/Test/PetClinic.

In your example, specifically:

  • Environment ID: Environments/EBA/EBA
  • Version ID: Applications/png/sso/png_sso/png_oct
  • Application ID: Applications/png/sso/png_sso
  • Name of application: png_sso
  • <environment-id>/<name-of-application>: Environments/EBA/EBA/png_sso

That would seem to work for your example...do you know whether it would also work for other cases?

Regards

Andrew

Andrew Phillips 0 votes
0
Avatar

Hi Andrew,

Yeah, but I was hoping top be able to get the deployed application programatically, via API.  So I was hoping if the user provided Environments/EBA/EBA and the version of the composite package they wanted to deploy i.e. Applications/png/sso/png_sso/png_oct then I could somehow find the deployed application and use it in my update call in the API.   

deployment/prepare/update/?environment=Environments/EBA/EBA&version=Applications/png/sso/png_sso/png_oct&deployedApplication=Environments/EBA/EBA/png_sso

Does that make sense?

Bernie

 

Bernie Bonn 0 votes
0
Avatar

> Does that make sense?

Yes, makes perfect sense. I'm just not sure there is an API call that does what you want :-( GET /deployment/exists is very close, but it only returns true or false, not the ID of the udm.DeployedApplication if that exists.

Does the <environment-id>/<name-of-application> formula not work for some of your applications, or is this questions related more to a style preference?

Regards

Andrew

Andrew Phillips 0 votes
0
Avatar

Hi There,

I wanted to circle back on this a bit. I thought I had a script that was executing control tasks on "targeted" infrastructure. What I found out was that I was looping through a mapped deployment of a composite package, which included all the deployeds and infrastructure not what was "targeted". Bummer.

Anyway, I was wondering if anyone had any ideas or if it is an enhancement request to get that info into he REST API.

So basically I prepare an update, then map, then I was hoping validate (all done via rest) would give me only the deployeds in the plan i.e. targeted for this particular deployment. But no dice, again it is everything.

I noticed if I post a preview using the output of the mapping step, I get the actual plan which is close. It gives me this:

<description>Delete reportingUser_properties from Infrastructure/non_windows/jumpboxes/pngdep01_n0</description>

Which I suppose I could parse, but would be nicer if I had a <container> tag for each thing that was actually being deployed.

Any ideas? I have been referencing this post to get me this far:

https://support.xebialabs.com/hc/communities/public/questions/201999585-How-to-prepare-validate-and-start-a-deployment-using-the-XL-Deploy-REST-API?locale=en-us

Thanks!
Bernie

Bernie Bonn 0 votes