curl cmd to redeploy an existing revision as a new revision

After the deployment of a new XACML or an updated XACML, the proxy needs redeployment to refresh. In order to make the deployment seemless, we need to save the existing revision[say 10] as a new revision[as 11]. We're preparing a shell script to make curl calls to redeploy an existing proxy as a new revision.

Is there a curl cmd to use the same existing revision in an environment and save it as a new revision without supplying the proxy bundle zip along with the cmd?

0 19 827
19 REPLIES 19

Hi @vbalan,

If you just need to redeploy the proxy then you can use the " Undeploy" and " Deploy" management APIs to achieve your goal.

Otherwise, you'll have to "Export" the currently deployed revision as bundled zip and then "Import" the same zip as a new revision of that proxy. The result will be a new revision of the same API proxy.

Hope this helps!

Hi Mohammed, thanks for the response.

Our requirement is to make it seemless. So if we undeploy the proxy first, it'll create an outage and also stops the flow of in-flight transactions.

We've got to deploy a new revision first from the existing revision[while the existing revision is still deployed] and then deploy that new revision[which automatically undeploys the previous revision].

Currently we're able to achieve this through the UI.

We would like to automate these steps using curl cmds from a shell script.

Hi @vbalan,

There is a powershell module available for automating any of the admin tasks using CLI.

Please check this repository:

https://github.com/DinoChiesa/Edge-Powershell-Admin

For doing a refresh you'll have to follow three step process:

1. Get the latest deployed revision, use below power shell command.

Get-EdgeApiDeployment -Name oauth2-pwd-cc | Format-List

2. Download the bundle, replace the revision number extracted from above

 Export-EdgeApi -Name oauth2-pwd-cc -Revision $revisioinNumber

3. Import the bundle as a new revision

Import-EdgeApi -Name oauth2-pwd-cc -Source oauth2-pwd-cc-r8-20160805-175438.zip

Off course you'll have to do some string extraction and replacements based on your requirements.

Hope this helps!

So that's still requiring us to use the bundle again, which we could achieve through the curl cmds. It seems like the 'save as new Revision' in GUI is not available through CLI[which is what we're looking for...]

No, I think the "save as new revision" is basically doing the above!

Hi @Dino

It would be great if we could have a cmd to run from CLI that could just save an existing revision as new revision, because having to use a regular deployment using a bundle requires us to run the datamasking and related tasks as well. In my opinion, running the deploy from CLI using the proxy bundle isn't the same as "save as new revision".

Imagine a scenario where the XACMLs are deployed by a team that doesn't handle the Apigee code [Like the IAM team]. They just need to worry about the XACMLs and not the proxy code bundle. For them, the task is all about deploying XACML and making sure that the existing proxy picks it up.

Hi @vbalan - I don't understand your example about XACMLs. I don't see how that would affect the existing proxy. Surely I'm missing something. If the XACMLs are remote with respect to the proxy, and the URL at which the XACMLs can be retrieved remains the same, then the proxy need not change at all. so anyway, I don't see what XACML updates has to do with anything. Let's put that aside.

As for your prior comment, you wrote:

In my opinion, running the deploy from CLI using the proxy bundle isn't the same as "save as new revision".

I don't know what this means either. But let me put that aside and try to clarify the situation. The way the UI works - when you have the API Proxy editor open, the Apigee UI holds in memory all of the existing API Proxy "stuff" - all of the policies, all of the endpoint definitions (proxy and target), all of the resources, including JS, XSL, Java JARs... When you click "Save as New Revision", the UI posts all of that data back to the Apigee Edge management server.

So if you would like to emulate that via a command-line request, something you could automate, then you need to zip up all the materials for the API Proxy bundle, and invoke the management API that does proxy import . The import looks like this:

CURL -X POST -H "Content-Type: application/octet-stream" \
   "${mgmtserver}/v1/o/${orgname}/apis?action=import&name=${proxyname}" \
   -T ${bundleZip} 

The powershell Export + Import commands that the other responder had suggested... they do exactly this. But of course you do not need powershell to do this; that's just a convenience wrapper around the RESTful API. You can twiddle the API with anything that does HTTP, like curl, or nodejs, or whatever.

In our scenario, XACMLs are bundled into a Policy.jar and pushed to Apigee Edge by the Identity and Acces Management team. If the updated XACMLs have to be picked up by the proxy, we have to un-deploy and redeploy the apiproxy.

If the Policy JAR is part of the bundle that gets deployed as an API Proxy, then... you want to import a new revision of the proxy and deploy it.

On the other hand I wouldn't want to hard-code the XACMLs into the proxy. Why not make them available externally, either as something stored in KVM, or available on an external service (chained proxy)? There's gotta be a better way than bundling them into a Policy.jar

For us, Policy.jar is not a part of the api proxy bundle.

It's uploaded using a separate curl cmd.

It's kept under org > env > resources/java/policy.jar

This is why we don't have to redeploy the bundle as a whole, but just need to "save as new revision" the existing bundle in Edge to pick up the latest policy.jar.

Ahh, I see. Sounds like you just need to undeploy/redeploy.

Hey @vbalan

You have to include the zip bundle in the curl to create a new revision. It seems like you have already seen this management API call to upload a new proxy.

However, before you write a script, you should review our maven deployment plugin to see if this command line tool will meet your needs. We also have a grunt deployment plugin as well. Both tools allow you to upload and deploy proxies; they also include a variety of other commands that help with deployment automation.

Hi @swilliams,

thanks for the response.

So it would seem there's no way to do seamless deployment of proxies through cmd line when there's no change in the proxy itself, but just to refresh it to pick up the new xacml.


@vbalan

Where is the XACML is stored? You said there are no changes to the bundle, but it needs to be redeployed to pick up the changes to the XACML.

What does XACML have to do with anything? This remark is confusing.

I was trying to drive the discussion to why @vbalan needs to save the proxy as a new revision every time the XCAML is updated. But he responded to my question above.

In our scenario, XACMLs are bundled into a Policy.jar and pushed to Apigee Edge by the Identity and Acces Management team. If the updated XACMLs have to be picked up by the proxy, we have to un-deploy and redeploy the apiproxy. 

redeployproxy.txt

So here's my solution as a shell script.

It does require the bundle zip which it will download from Edge.

In our org, we have 3 environments in np in the same ORG.

Therefore the ORG might have the latest revision as 100 but an environment ADT inside that ORG may be at revision 80, for a given proxy.

This script will get both the revision numbers.

Downloads the latest revision from environment ADT[say 80] and uploads it to the ORG as revision 101.

Then it does a seamless deploy by giving a 10 sec delay to the previously deployed proxy to finish executing in-flight transactions.

Rename the attached file with .sh extension.

Help Menu

$ ./redeployProxy.sh -h

set your username and password in 2 variables

$ UNAME='blah@blah.com'

$ MYPASS='you_wish_:P '

invoke the script-

$ ./redeployProxy.sh -e sandbox -a apiProxy-learn-edge -u $UNAME -p $MYPASS

Sounds like you found a good solution. Have you considered whether you need to retain 80 or 100 revisions ? You could write a little more logic to cull the list to keep it at 15 or less.

80 or 100 was just some random number i picked to state my point.

Although, in our ADT, QAT, SPT environments the revisions are much higher than 10, since they all reside in the same non-prod ORG but at different revisions.