Service Virtualization

Expand all | Collapse all

redeploy option with deployMar REST API

  • 1.  redeploy option with deployMar REST API

    Posted 04-20-2016 03:13 PM

    When using VSManager.exe to deploy a Virtual Service mar file, there is both a --deploy and a --redeploy option. When using the REST API, there seems to only be a deploy equivalent (the 'deployMar' API call) but no equivalent for redeploy. Is that correct, or have I missed something?



  • 2.  Re: redeploy option with deployMar REST API

    Broadcom Employee
    Posted 04-22-2016 02:10 PM

    Did you try to deploy a new mar and then re-deploy with the same API call and it did not work?

     

    Thanks!



  • 3.  Re: redeploy option with deployMar REST API

    Posted 04-27-2016 03:26 AM

    If you deploy again, it will overlay previously deployed..

     

    the commandline surfaces the difference, which u can do with the rest api as well..

    get the existing services, and if the names match it is a redeploy.

     

    I use this in my scripts to validate that the service you want to stop is already there and running, etc



  • 4.  Re: redeploy option with deployMar REST API

    Posted 04-27-2016 12:36 PM

    Hi,

    Let me elaborate - if I execute:

    curl -u USERNAME:PASSWORD -F "file=@FILENAME.mar" http://LISAHOST:LISAPORT/api/Dcm/VSEs/VSE1/actions/deployMar

    Where that service name does not exist, the operation is successful. If I then execute it again I get the error "There is already a service with the name SERVICENAME".

    I should add that this is LISA 7.5.1!



  • 5.  Re: redeploy option with deployMar REST API

    Posted 05-02-2016 11:37 AM

    I did a sccript in groovy to use the API REST for the deploy:

     

    import org.apache.http.entity.mime.MultipartEntityBuilder

    import org.apache.http.entity.mime.content.ByteArrayBody

    import groovyx.net.http.HttpResponseDecorator

     

    def httpBuilder = new HTTPBuilder("http://XXXXXXXX:1505/api/Dcm/VSEs/${vse}/actions/deployMar")

    String filename = "${vsiFileDir}/${testname}.mar"

    def login = "${username}:${password}".bytes.encodeBase64().toString()

    httpBuilder.request (Method.POST) { multipartRequest ->

           headers.'Authorization' ="Basic ${login}"

           MultipartEntityBuilder multipartRequestEntity = new MultipartEntityBuilder()

           multipartRequestEntity.addPart('file', new ByteArrayBody(

           IOUtils.toByteArray(new FileInputStream(new File(filename)))))

           multipartRequest.entity = multipartRequestEntity.build()

     

           response.success = { HttpResponseDecorator resp3, data3 ->

                if (resp3.getStatus() == 201) { //201 created OK

                     log.info("Deploy Mar OK")

                } else {

                     log.info("Failure of deploy Mar")

                }

           }

           response.failure = { HttpResponseDecorator resp3, data3 ->

                log.error("Failure of deploy Mar")

           }

      }

     

    Please let me know if you have any questions.



  • 6.  Re: redeploy option with deployMar REST API

    Posted 05-03-2016 04:52 AM

    Hi Relbou,

     

    Well, my main question would be what your findings were using this code. Were you able to call this code twice in a row with a successful response code? Did you get a successful response the first time and an error the second time, which would be conistent with what I am experiencing? What version of LISA where you using?

     

    I very much appreciate the effort you put in providing actual code in your reply, but my query was around the API behaviour rather than how to call the API. Your finidngs when you executed the code are much more valuable than the code itself!



  • 7.  Re: redeploy option with deployMar REST API

    Posted 05-03-2016 05:12 AM

    For reply to your question: you don't have a redeploy function in REST API but you can do a delete and a deploy.



  • 8.  Re: redeploy option with deployMar REST API

    Posted 05-03-2016 05:16 AM

    Ah, thank you, that's what I was trying to verify. It's a shame, becasue the redeploy of VSManager means much less downtime (not zero, but minimal). Whereas the delete and deploy via the REST API will certainly mean more downtime and will push me down the VSManager route, even though I'd prefer to use the REST API with its superior output...



  • 9.  Re: redeploy option with deployMar REST API

    Posted 05-03-2016 05:31 AM

    import java.util.concurrent.CancellationException

    import groovyx.net.http.HTTPBuilder

    import static groovyx.net.http.Method.GET

    import static groovyx.net.http.Method.POST

    import static groovyx.net.http.Method.DELETE

    import static groovyx.net.http.Method.PUT

    import static groovyx.net.http.ContentType.TEXT

    import static groovyx.net.http.ContentType.JSON

    import static groovyx.net.http.ContentType.XML

    import groovy.xml.XmlUtil

    import java.util.logging.Logger

    import java.nio.file.Files

    import java.nio.file.FileSystems

    import org.apache.http.entity.mime.MultipartEntityBuilder

    import org.apache.http.entity.mime.content.ByteArrayBody

    import groovyx.net.http.HttpResponseDecorator

    import org.apache.commons.io.IOUtils

     

    .....

     

    def testname  = projectProperties.TEST_NAME

    def vse = projectProperties.VSE

    def password = projectProperties.PASSWORD

    def username = projectProperties.USERNAME

    def vsiFileDir    = projectProperties.GENERATED_VS_FOLDER.replace("\\", "/").replace("%20", " ")

     

     

    def httpverif = new HTTPBuilder()

    def httpverif2 = new HTTPBuilder()

     

     

    def url = "http://xxxxxxxx:1505/api/Dcm/VSEs/${vse}/${testname}"

     

     

    logger.info("${vsiFileDir}")

     

     

     

     

    httpverif.request( url, GET, TEXT ) {

         def login = "${username}:${password}".bytes.encodeBase64().toString()

         headers.'Authorization' = "Basic ${login}"

         headers.'accept'='application/vnd.ca.lisaInvoke.virtualService+xml'

         

          response.'200' = { resp, reader ->

                println "======================================="

                println "============ Response 200 ============="

                println "======================================="

     

                def url1 = "http://xxxxxxxxxxxxx:1505/api/Dcm/VSEs/${vse}/${testname}"

                httpverif2.request( url1, DELETE, TEXT ) {

                     headers.'Authorization' = "Basic ${login}"

                     headers.'accept'='application/xml'

     

                     println "======================================="

                     println "====== DELETE of Virtual Service  ====="

                     println "======================================="

     

                     response.'204' = { resp1, reader1 ->

     

                          println "======================================="

                          println "============ Response 204 ============="

                          println "======================================="

     

                          def httpBuilder = new HTTPBuilder("http://xxxxxxxxxxx:1505/api/Dcm/VSEs/${vse}/actions/deployMar")

                          String filename = "${vsiFileDir}/${testname}.mar"

                          httpBuilder.request(POST) { multipartRequest ->

                               headers.'Authorization' ="Basic ${login}"

                              headers.'accept'='application/vnd.ca.lisaInvoke.virtualService+xml'

                               MultipartEntityBuilder multipartRequestEntity = new MultipartEntityBuilder()

                               multipartRequestEntity.addPart('file', new ByteArrayBody(

                               IOUtils.toByteArray(new FileInputStream(new File(filename))),"${testname}.mar"))

                               multipartRequest.entity = multipartRequestEntity.build()

     

     

                               response.success = { HttpResponseDecorator resp3, data3 ->

                                    if (resp3.getStatus() == 201) { //201 created OK

                                         println "Deploy Mar OK"

                                    } else {

                                         println "Failure of deploy Mar"

                                    }

                               }

                               response.failure = { HttpResponseDecorator resp3, data3 ->

                                    println "Failure of deploy Mar"

                               }

                          }

                          println "======================================="

                          println "====== Virtual Service is deploy ======"

                          println "======================================="

                    }

                }

           }

           response.'500' = { resp2, reader2 ->

     

                          println "======================================="

                          println "============ Response 500 ============="

                          println "======================================="

     

                          def httpBuilder = new HTTPBuilder("http://xxxxxxx:1505/api/Dcm/VSEs/${vse}/actions/deployMar")

                             String filename = "${vsiFileDir}/${testname}.mar"

     

                             httpBuilder.request(POST){ multipartRequest ->

                                    headers.'Authorization' ="Basic ${login}"

                                    headers.'accept'='application/vnd.ca.lisaInvoke.virtualService+xml'

                                    MultipartEntityBuilder multipartRequestEntity = new MultipartEntityBuilder()

                                    multipartRequestEntity.addPart('file', new ByteArrayBody(

                                    IOUtils.toByteArray(new FileInputStream(new File(filename))),"${testname}.mar"))

                                    multipartRequest.entity = multipartRequestEntity.build()

     

     

                                    response.success = { HttpResponseDecorator resp3, data3 ->

                                         If (resp3.getStatus() == 201) { //201 created OK

                                              println "Deploy Mar OK"

                                         } else {

                                              println "Failure of deploy Mar"

                                         }    

                                    }

                                    response.failure = { HttpResponseDecorator resp3, data3 ->

                                         println "Failure of deploy Mar"

                                    }

                               }

     

                               println "======================================="

                               println "====== Virtual Service is deploy ======"

                               println "======================================="

                        }

     

    }

     

    println "======================================="

    println "============ End of script ============"

    Println "======================================="