Using REST Services to Manage WebLogic Server

Overview

Purpose

This tutorial shows you how to use REST requests to manage WebLogic Server domains.

Time to Complete

Approximately 1 hour

Introduction

This tutorial shows you how to use REST services to manage different aspects of a WebLogic Server 12.1.3 domain, including:

  • Servers and clusters
  • Application deployments
  • JDBC data sources

Hardware and Software Requirements

The following is a list of hardware and software requirements:

  • Web browser
  • Oracle Java SE 1.7.0_15 or later (NOT Java SE 1.8!) (download)
  • Oracle Database 11g or later (Express Edition may work as well but has not been tested) (download)
  • WebLogic Server 12.1.3 (download)
  • Linux or equivalent operating system with root access for making some configuration changes
  • Minimum RAM: 4GB
  • Minimum disk space: 20GB

Prerequisites

Before starting this tutorial, you should:

  • Install all of the software listed in the Hardware and Software Requirements section
  • Reference: Node Manager tutorial
  • Reference: Configure JDBC Data Source
  • Reference: Using RESTful Management Services
  • Created a WebLogic Server domain

    Entity Domain Settings
    Mode Development
    Template

    Basic WebLogic Server Domain [wlserver]

    Admin User weblogic/Welcome1
    AdminServer hostname:7001
    Node Manager Per-Domain
    Host1: hostname1:5556
    Credentials: weblogic/Welcome1
    Machines machine1
    Node Manager: Host1:5556
    Clusters Configured cluster: cluster1
    Servers Two configured servers:
    server1 (machine1) Port 8001
    server2 (machine1) Port 8002
    Both servers are in cluster1


  • Started the WebLogic administration server

When your environment is configured continue with the next topic.

Enabling REST Management Services

You must enable REST management services before WebLogic can accept REST requests. Follow these steps to enable REST management services.

  1. Open the WebLogic administration console.

  2. Login to the administration console with the administrative user name and password you used to create your domain. The administrative user's credentials for my domain are weblogic and Welcome1.

  3. Click the domain node in the Domain Structure pane to view domain settings.

  4. Scroll down the page and click Advanced to view advanced settings at the domain level.

  5. Scroll down the page again and locate and select Enable RESTful Management Services to enable WebLogic to accept REST management requests.

  6. Save your changes.

  7. Restart the administration server for your changes to take effect.

Now that you have enabled REST management services, let's use REST requests to work with servers.

Managing Servers

REST management services enable you to manage the life cycle of WebLogic servers. Follow these steps to control the servers in your domain.

  1. Set up your scripting environment.

    Copy the rest.tar file to your lab environment and unpackage the files. These files are scripts you can use to execute REST requests against your domain.

    $ tar xvf rest.tar
    $ ls -l
    drwxr-xr-x 2 oracle oinstall 4096 Jul 18 08:26 answers
    -rwxr-xr-x 1 oracle oinstall  853 Jul 18 08:23 dep_deployAuction.sh
    -rwxr-xr-x 1 oracle oinstall  629 Jul 18 08:23 dep_list.sh
    -rwxr-xr-x 1 oracle oinstall  667 Jul 18 08:23 dep_undeployAuction.sh
    -rwxr-xr-x 1 oracle oinstall  700 Jul 18 08:27 ds_create.sh
    -rwxr-xr-x 1 oracle oinstall  648 Jul 18 08:24 ds_delete.sh
    -rwxr-xr-x 1 oracle oinstall  646 Jul 18 08:23 ds_getopt.sh
    -rwxr-xr-x 1 oracle oinstall  627 Jul 18 10:04 ds_listAll.sh
    -rwxr-xr-x 1 oracle oinstall  645 Jul 18 08:25 ds_list.sh
    -rwxr-xr-x 1 oracle oinstall  640 Jul 18 08:23 s_listAdmin.sh
    -rwxr-xr-x 1 oracle oinstall  636 Jul 18 08:23 s_listS1.sh
    -rwxr-xr-x 1 oracle oinstall  625 Jul 18 08:23 s_listServers.sh
    -rwxr-xr-x 1 oracle oinstall  643 Jul 18 08:23 s_startS1.sh
    -rwxr-xr-x 1 oracle oinstall  646 Jul 18 08:23 s_stopS1.sh
  2. Execute the following command to ensure that curl is in your PATH.

    $ which curl
  3. If curl is not in your PATH, then add /usr/bin to your PATH.

    $ export PATH=$PATH:/usr/bin
  4. Review each script in the gedit editor before executing the script. Examine how each script works.

    $ gedit [script-name] &
  5. View and then execute the following script to list all servers in the domain.

    $ ./s_listServers.sh
  6. You should see a successful response, a set of relative REST links, and entries (items) returned that represent the servers that are configured in the domain.

    * About to connect() to host01 port 7001 (#0)
    *   Trying 192.0.2.11... connected
    * Connected to host01 (192.0.2.11) port 7001 (#0)
    * Server auth using Basic with user 'weblogic'
    > GET /management/wls/latest/servers HTTP/1.1
    > Authorization: Basic d2VibG9naWM6V2VsY29tZTE=
    > User-Agent: curl/7.19.7 (x86_64-unknown-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
    > Host: host01:7001
    > X-Requested-By:MyClient
    > Accept:application/json
    > 
    < HTTP/1.1 200 OK
    < Date: Fri, 18 Jul 2014 09:05:35 GMT
    < Content-Length: 1230
    < Content-Type: application/json
    < Set-Cookie: JSESSIONID=CNxIuCuVUz3qmKI9G7RiwRzs95kjb3i_cVOe4RzauJZKtopEjvun!-1665012684; path=/; HttpOnly
    < 
    {
        "links": [
            {
                "rel": "parent",
                "uri": "http:\/\/host01:7001\/management\/wls\/latest"
            },
            {
                "rel": "items.name",
                "uri": "http:\/\/host01:7001\/management\/wls\/latest\/servers\/id\/AdminServer",
                "title": "AdminServer"
            },
            {
                "rel": "items.name",
                "uri": "http:\/\/host01:7001\/management\/wls\/latest\/servers\/id\/server1",
                "title": "server1"
            },
            {
                "rel": "items.name",
                "uri": "http:\/\/host01:7001\/management\/wls\/latest\/servers\/id\/server2",
                "title": "server2"
            }
        ],
        "items": [
            {
                "heapFreeCurrent": 116878240,
                "heapSizeCurrent": 278396928,
                "health": {"state": "ok"},
                "usedPhysicalMemory": 2964152320,
                "jvmProcessorLoad": 0,
                "activeHttpSessionCount": 0,
                "activeThreadCount": 7,
                "name": "AdminServer",
                "state": "running"
            },
            {
                "name": "server1",
                "state": "shutdown"
            },
            {
                "name": "server2",
                "state": "shutdown"
            }
        ]
    * Connection #0 to host host01 left intact
    * Closing connection #0
  7. View and then execute the following script to list the domain's AdminServer.

    $ ./s_listAdmin.sh

    Review the table below to learn more about the returned links.

    Links

    Relative Type Title URI Description
    parent
    none servers The parent object to AdminServer
    logs
    none servers/id/AdminServer/logs

    The top-level object for AdminServer logs

    action
    start servers/id/AdminServer/start Starts the AdminServer
    action
    restart servers/id/AdminServer/restart Restarts the AdminServer
    action
    suspend servers/id/AdminServer/suspend Suspends a started AdminServer
    action
    resume servers/id/AdminServer/resume Resumes a suspended AdminServer
    action
    shutdown servers/id/AdminServer/shutdown Shuts down a started AdminServer


    Items

    The only item returned is the AdminServer and associated statistics.

    "item": {
            "heapFreeCurrent": 91484336,
            "heapSizeCurrent": 278396928,
            "health": {"state": "ok"},
            "usedPhysicalMemory": 2981982208,
            "jvmProcessorLoad": 0,
            "activeHttpSessionCount": 0,
            "activeThreadCount": 4,
            "name": "AdminServer",
            "state": "running"
        }
    * Connection #0 to host host01 left intact
    * Closing connection #0
  8. View and then execute the following script to list server1.

    $ ./s_listS1.sh

    The only item returned is server1 and associated statistics. Because the server is shut down, there are no statistics to display.

    "item": {
            "name": "server1",
            "state": "shutdown"
        }
    * Connection #0 to host host01 left intact
    * Closing connection #0
  9. View and then execute the following script to start server1. Remember that your Node Manager should be running. This is a synchronous call and will take some time to finish.

    $ ./s_startS1.sh

    After the server starts, the response indicates the status of the operation, the job list URI as a link, and more information about the operation.

    {
        "messages": [{
            "message": "Started the server 'server1'.",
            "severity": "SUCCESS"
        }],
        "links": [{
            "rel": "job",
            "uri": "http:\/\/host01:7001\/management\/wls\/latest\/jobs\/server\/id\/server1:_2_start"
        }],
        "item": {
            "beginTime": 1405676787841,
            "endTime": 1405676804048,
            "status": "completed",
            "description": "Starting server1 server ...",
            "operation": "start",
            "serverName": "server1",
            "name": "_2_start",
            "id": "server1:_2_start",
            "type": "server"
        }
    * Connection #0 to host host01 left intact
    * Closing connection #0
  10. List server1 again.

    $ ./s_listS1.sh

    The response shows statistics for the server because it is running now.

    "item": {
            "heapFreeCurrent": 105886528,
            "heapSizeCurrent": 347602944,
            "health": {"state": "ok"},
            "usedPhysicalMemory": 2325405696,
            "jvmProcessorLoad": 0,
            "activeHttpSessionCount": 0,
            "activeThreadCount": 7,
            "name": "server1",
            "state": "running"
        }
    * Connection #0 to host host01 left intact
    * Closing connection #0
  11. Warning: Do not execute this script!

    Review the s_stopS1.sh script. This script stops server1 if it is running. You are not stopping the server because you are going to deploy an application to it later.

  12. Experiment on your own for a few minutes. Remember that you should start server1 if you shut it down so that it is ready for other tasks.

Now that you have used REST requests to manage servers, let's use REST requests to work with data sources.

Managing Data Sources

REST management services enable you to manage JDBC data sources in your WebLogic domains. Follow these steps to manage data sources in your domain.

  1. View and then execute the following script to list all the data sources in the domain.

    $ ./ds_listAll.sh

    In my domain, there are no configured data sources and I get an empty response. If you did not configure a data source, then you should get the same result.

    "items": []
    * Connection #0 to host host01 left intact
    * Closing connection #0
  2. View and then execute the following script to obtain a data source template from WebLogic. When you execute this script, it redirects the response into a file called jdbc.options in your current directory. This file contains a default template for creating a data source. You must modify this file to provide settings for the data source you want to create and pass this data in another REST request to create the data source.

    $ ./ds_getopt.sh
  3. Open the jdbc.options file for editing.

    $ gedit jdbc.options &
  4. The solution file is located in the answers/jdbcMyDS.options file. You should analyze the differences between your jdbc.options file and the solution file to make your modifications. Your settings will not be exactly the same as mine, so change them appropriately for your environment.

  5. View and then execute the following script to create your data source.

    $ ./ds_create.sh

    The request will run for a short time and return a response with the status of the request.

    {"messages": [{
        "message": "Successfully created 'MyDataSource-0'.",
        "severity": "SUCCESS"
    * Connection #0 to host host01 left intact
    * Closing connection #0
  6. Execute the ds_listAll.sh script again to list all the data sources in the domain.

    $ ./ds_listAll.sh

    The response should now have detailed information about your newly configured data source.

    "items": [{
            "targets": ["cluster1"],
            "jdbcDataSourceParams": {
                "keepConnAfterGlobalTx": false,
                "keepConnAfterLocalTx": true,
                "rowPrefetch": false,
                "jndiNames": ["ds.myds2"],
                "rowPrefetchSize": 48,
                "streamChunkSize": 256,
                "algorithmType": "failover",
                "connectionPoolFailoverCallbackHandler": null,
                "failoverRequestIfBusy": false,
                "dataSourceList": null,
                "globalTransactionsProtocol": "two phase commit",
                "scope": "global"
            },
            "jdbcConnectionPoolParams": {
                "jdbcXaDebugLevel": 10,
                "wrapTypes": true,
                "credentialMappingEnabled": false,
                "pinnedToThread": false,
                "wrapJdbc": true,
                "identityBasedConnectionPoolingEnabled": false,
                "removeInfectedConnections": true,
                "ignoreInUseConnectionsEnabled": true,
                "driverInterceptor": "",
                "connectionHarvestMaxCount": 1,
                "connectionHarvestTriggerCount": -1,
                "minCapacity": 1,
                "profileType": 0,
                "connectionLabelingCallback": "",
                "maxCapacity": 15,
                "highestNumWaiters": 2147483647,
                "connectionReserveTimeoutSeconds": 10,
                "connectionCreationRetryFrequencySeconds": 0,
                "inactiveConnectionTimeoutSeconds": 0,
                "statementCacheSize": 10,
                "statementCacheType": "least recently used",
                "statementTimeout": -1,
                "countOfTestFailuresTillFlush": 2,
                "countOfRefreshFailuresTillDisable": 2,
                "loginDelaySeconds": 0,
                "secondsToTrustAnIdlePoolConnection": 10,
                "initialCapacity": 1,
                "shrinkFrequencySeconds": 900,
                "testFrequencySeconds": 120,
                "testTableName": "SQL ISVALID",
                "testConnectionsOnReserve": false,
                "profileHarvestFrequencySeconds": 300,
                "initSql": "",
                "fatalErrorCodes": ""
            },
            "jdbcDriverParams": {
                "useXaDataSourceInterface": true,
                "usePasswordIndirection": false,
                "driverName": "oracle.jdbc.xa.client.OracleXADataSource",
                "url": "jdbc:oracle:thin:@host02.example.com:1521:orcl",
                "systemProperties": [],
                "properties": [{
                    "name": "user",
                    "value": "oracle"
                }]
            },
            "aggregateMetrics": {
                "prepStmtCacheAccessCount": 0,
                "prepStmtCacheAddCount": 0,
                "prepStmtCacheDeleteCount": 0,
                "prepStmtCacheCurrentSize": 0,
                "prepStmtCacheHitCount": 0,
                "prepStmtCacheMissCount": 0,
                "currCapacity": 1,
                "numAvailable": 1,
                "highestNumAvailable": 1,
                "numUnavailable": 0,
                "highestNumUnavailable": 0,
                "failuresToReconnectCount": 0,
                "connectionDelayTime": 616,
                "activeConnectionsCurrentCount": 0,
                "waitingForConnectionCurrentCount": 0,
                "activeConnectionsHighCount": 0,
                "activeConnectionsAverageCount": 0,
                "reserveRequestCount": 0,
                "failedReserveRequestCount": 0,
                "waitingForConnectionHighCount": 0,
                "waitingForConnectionTotal": 0,
                "waitingForConnectionSuccessTotal": 0,
                "waitingForConnectionFailureTotal": 0,
                "waitSecondsHighCount": 0,
                "connectionsTotalCount": 1,
                "currCapacityHighCount": 1,
                "leakedConnectionCount": 0,
                "state": "Running"
            },
            "dataSourceMetrics": [{
                "prepStmtCacheAccessCount": 0,
                "prepStmtCacheAddCount": 0,
                "prepStmtCacheDeleteCount": 0,
                "prepStmtCacheCurrentSize": 0,
                "prepStmtCacheHitCount": 0,
                "prepStmtCacheMissCount": 0,
    
                "currCapacity": 1,
                "numAvailable": 1,
                "highestNumAvailable": 1,
                "numUnavailable": 0,
                "highestNumUnavailable": 0,
                "failuresToReconnectCount": 0,
                "connectionDelayTime": 616,
                "activeConnectionsCurrentCount": 0,
                "waitingForConnectionCurrentCount": 0,
                "activeConnectionsHighCount": 0,
                "activeConnectionsAverageCount": 0,
                "reserveRequestCount": 0,
                "failedReserveRequestCount": 0,
                "waitingForConnectionHighCount": 0,
                "waitingForConnectionTotal": 0,
                "waitingForConnectionSuccessTotal": 0,
                "waitingForConnectionFailureTotal": 0,
                "waitSecondsHighCount": 0,
                "connectionsTotalCount": 1,
                "currCapacityHighCount": 1,
                "leakedConnectionCount": 0,
                "serverName": "server1",
                "state": "Running"
            }],
            "name": "MyDataSource-0"
        }]
    * Connection #0 to host host01 left intact
    * Closing connection #0
  7. Navigate to Services > Data Sources within the WebLogic administration console to verify that your data source was created.

  8. Review the ds_delete.sh script. This script deletes the data source. It is ok to delete the data source because it is not used again in this tutorial.

  9. Experiment on your own for a few minutes.

Now that you have used REST requests to work with data sources, let's use REST requests to work with deployments.

Managing Deployments

REST management services enable you to manage Java EE application deployments in your WebLogic domains. Follow these steps to manage application deployments in your domain.

  1. View and then execute the following script to list all the applications that are deployed in the domain.

    $ ./dep_list.sh

    In my domain, there are no configured applications and I get an empty response. If you did not configure an application, then you should get the same result.

    "items": []
    * Connection #0 to host host01 left intact
    * Closing connection #0
  2. Upload the SimpleAuctionWebApp.war application to your environment.

  3. Open the dep_deployAuction.sh script for editing.

    $ gedit dep_deployAuction.sh &
  4. Modify the script so that the deploymentPath parameter is set to the location where you uploaded the application.

    deploymentPath: '[your-upload-location]/SimpleAuctionWebApp.war',
  5. View and then execute the following script to deploy the application.

    $ ./dep_deployAuction.sh

    The request will run for a short time and return a response with the status of the request.

    {
        "messages": [{
            "message": "Deployed the application 'SimpleAuctionWebApp'.",
            "severity": "SUCCESS"
        }],
        "links": [{
            "rel": "job",
            "uri": "http:\/\/host01:7001\/management\/wls\/latest\/jobs\/deployment\/id\/0"
        }],
        "item": {
            "deploymentName": "SimpleAuctionWebApp",
            "beginTime": 1405681038430,
            "endTime": 1405681040918,
            "status": "completed",
            "targets": [{
                "status": "completed",
                "errors": [],
                "name": "AdminServer",
                "type": "server"
            }],
            "description": "[Deployer:149026]deploy application SimpleAuctionWebApp on AdminServer.",
            "operation": "deploy",
            "name": "ADTR-0",
            "id": "0",
            "type": "deployment"
        }
    * Connection #0 to host host01 left intact
    * Closing connection #0
  6. Execute the dep_list.sh script again to list all the applications in the domain.

    $ ./dep_list.sh

    The response should now have detailed information about your newly deployed application.

    "items": [{
            "targets": ["AdminServer"],
            "deploymentPath": "\/practices\/obes\/labs\/apps\/SimpleAuctionWebApp.war",
            "name": "SimpleAuctionWebApp",
            "state": "active",
            "type": "application",
            "displayName": "SimpleAuctionWebApp"
        }]
    * Connection #0 to host host01 left intact
    * Closing connection #0
  7. Navigate to Deployments within the WebLogic administration console to verify that your application was deployed.

  8. Test the application by browsing to http://[your-host]:[7001]/SimpleAuctionWebApp.

  9. Click Create Default Data and confirm Yes to create data in-memory for the application. The application does not store data in the database and this step is required for the application to function properly.

  10. Click Go Home to return to the main page and click View Auction List to view the application's auctions. You should see a list similar to the image below.

  11. Review the dep_undeployAuction.sh script. This script undeploys the application. It is ok to undeploy the application because it is not used again in this tutorial.

  12. Experiment on your own for a few minutes.

Now that you have used REST to perform some basic tasks, take some time to experiment on your own.

Experimenting with REST

This course provides the basics to get started with REST services to manage WebLogic domains. This section leaves you to work on your own to experiment with your environment to try using REST in other ways. There are no instructions in this section, but some possible topics for exploration are listed below.

  • Deploying libraries and applications that reference them
  • Suspending and resuming servers
  • Performing more sophisticated deployment operations that involve uploading application archives from a non-WebLogic location
  • Suspending and resuming data sources
  • Viewing server logs

Congratulations! Now you know how to manage WebLogic Server domains with REST.

To navigate this Oracle by Example tutorial, note the following:

Topic List:
Click a topic to navigate to that section.
Expand All Topics:
Click the button to show or hide the details for the sections. By default, all topics are collapsed.
Hide All Images:
Click the button to show or hide the screenshots. By default, all images are displayed.
Print:
Click the button to print the content. The content that is currently displayed or hidden is printed.

To navigate to a particular section in this tutorial, select the topic from the list.