09 April 2015

Deploying applications remotely with WebLogic REST Management Interface

WebLogic 12.1.3 provides a fully documented REST Management Interface that enables deployment and management operations to be performed using REST calls.

The table of contents from the documentation lists the set of operations available:
To use the REST Management Interface, it first must be enabled for a domain. This can be done from the WebLogic Console.

Domain > Configuration > General [Advanced] > Enable RESTful Management Services




To deploy an application to a remote server, the REST Management Interface provides the ability to upload an application archive and execute the deployment operation:
To perform this type of deployment operation a HTTP POST on the deployment URL is invoked specifying:
  1. The HTTP Header of multipart/form-data;
  2. The application archive is supplied as form field deployment;
  3. The deployment information specified using the form field model in which the application name, targets and other attributes are supplied;
Using curl this looks like the following:

$ curl \
  --user weblogic:welcome1 \
  -H X-Requested-By:TestForRest \
  -H Accept:application/json \
  -H Content-Type:multipart/form-data \
  -F "model={
    name: 'basicwebapp',
    targets: [ 'AdminServer' ]
  }" \
  -F "deployment=@/tmp/basicwebapp.war" \
  -X POST http://adc2101001.us.oracle.com:7001/management/wls/latest/deployments/application

When this REST call is made with curl, the application archive specified as @/tmp/basicwebapp.war is uploaded as a binary file using the form field deployment and the configuration information supplied in the model form parameter used to define and perform the deployment.

The response returned from the REST call contains a payload with the result of the operation that was performed.

{
    "messages": [{
        "message": "Deployed the application 'basicwebapp'.",
        "severity": "SUCCESS"
    }],
    "links": [{
        "rel": "job",
        "uri": "http://adc2101001:7001/management/wls/latest/jobs/deployment/id/3"
    }],
    "item": {
        "name": "ADTR-3",
        "id": "3",
        "type": "deployment",
        "status": "completed",
        "beginTime": 1428541581923,
        "endTime": 1428541584150,
        "targets": [{
            "name": "AdminServer",
            "type": "server",
            "errors": [],
            "status": "completed"
        }],
        "description": "[Deployer:149026]deploy application basicwebapp on AdminServer.",
        "operation": "deploy",
        "deploymentName": "basicwebapp"
    }
}

Further information about the deployment resource can be obtained using a further REST call, which provides links to operations that can be performed on the application, URLs to access the application, context-paths for registered servlets, runtime data and other useful information.

$ curl \
  --user weblogic:welcome1 \
  -H Accept:application/json \
  http://adc2101001:7001/management/wls/latest/deployments/application/id/basicwebapp

Which returns a response containing a payload with details of the deployment:

{
    "links": [
        {
            "rel": "parent",
            "uri": "http://adc2101001:7001/management/wls/latest/deployments/application"
        },
        {
            "rel": "action",
            "uri": "http://adc2101001:7001/management/wls/latest/deployments/application/id/basicwebapp/redeploy",
            "title": "redeploy"
        },
        {
            "rel": "action",
            "uri": "http://adc2101001:7001/management/wls/latest/deployments/application/id/basicwebapp/update",
            "title": "update"
        },
        {
            "rel": "action",
            "uri": "http://adc2101001:7001/management/wls/latest/deployments/application/id/basicwebapp/start",
            "title": "start"
        },
        {
            "rel": "action",
            "uri": "http://adc2101001:7001/management/wls/latest/deployments/application/id/basicwebapp/stop",
            "title": "stop"
        },
        {
            "rel": "bindables",
            "uri": "http://adc2101001:7001/management/wls/latest/deployments/application/id/basicwebapp/bindables"
        }
    ],
    "item": {
        "name": "basicwebapp",
        "state": "active",
        "type": "application",
        "displayName": "basicwebapp",
        "targets": ["AdminServer"],
        "planPath": "/scratch/sbutton/Oracle/Middleware/user_projects/domains/arq_domain/servers/AdminServer/upload/basicwebapp/plan/Plan.xml",
        "urls": ["http://adc2101001:7001/basicwebapp"],
        "openSessionsCurrentCount": 1,
        "sessionsOpenedTotalCount": 1,
        "servlets": [
            {
                "servletName": "JspServlet",
                "contextPath": "/basicwebapp",
                "aggregateMetrics": {
                    "executionTimeTotal": 0,
                    "invocationTotalCount": 0,
                    "reloadTotalCount": 0,
                    "executionTimeHigh": 0,
                    "executionTimeLow": 0
                },
                "servletMetrics": [{
                    "serverName": "AdminServer",
                    "executionTimeTotal": 0,
                    "invocationTotalCount": 0,
                    "reloadTotalCount": 0,
                    "executionTimeHigh": 0,
                    "executionTimeLow": 0
                }]
            },
            {
                "servletName": "Faces Servlet",
                "contextPath": "/basicwebapp",
                "aggregateMetrics": {
                    "executionTimeTotal": 22,
                    "invocationTotalCount": 1,
                    "reloadTotalCount": 1,
                    "executionTimeHigh": 22,
                    "executionTimeLow": 22
                },
                "servletMetrics": [{
                    "serverName": "AdminServer",
                    "executionTimeTotal": 22,
                    "invocationTotalCount": 1,
                    "reloadTotalCount": 1,
                    "executionTimeHigh": 22,
                    "executionTimeLow": 22
                }]
            },
            {
                "servletName": "FileServlet",
                "contextPath": "/basicwebapp",
                "aggregateMetrics": {
                    "executionTimeTotal": 0,
                    "invocationTotalCount": 0,
                    "reloadTotalCount": 0,
                    "executionTimeHigh": 0,
                    "executionTimeLow": 0
                },
                "servletMetrics": [{
                    "serverName": "AdminServer",
                    "executionTimeTotal": 0,
                    "invocationTotalCount": 0,
                    "reloadTotalCount": 0,
                    "executionTimeHigh": 0,
                    "executionTimeLow": 0
                }]
            }
        ],
        "ejbs": [],
        "deploymentPath": "servers/AdminServer/upload/basicwebapp/app/basicwebapp.war",
        "applicationType": "war",
        "health": {"state": "ok"}
    }
} 

The documentation provides extensive coverage of the many resources and entity types that can be reached via the REST Management Interface.