WebLogic Server 12c (12.2.1): Using REST Services to Manage WebLogic Server


Options



Before You Begin

Purpose

This tutorial shows you how to use REST requests to manage WebLogic Server 12c (12.2.1) domains.

Time to Complete

Approximately 1 hour

Background

This tutorial shows you how to use REST services to manage different aspects of a WebLogic Server 12c (12.2.1) domain, including:

  • Servers and clusters
  • Application deployments
  • JDBC data sources

What Do You Need?

The following is a list of hardware and software requirements:

  • Web browser
  • Oracle Java SE 1.8.0_60-b27 (download)
  • Oracle Database 12c or later (Express Edition may work as well but has not been tested) (download)
  • WebLogic Server 12.2.1 (download)
  • Linux or equivalent operating system with root access for making some configuration changes
  • Minimum RAM: 4GB
  • Minimum disk space: 20GB

Before starting this tutorial, you should:

  • Install all of the software listed above
  • Follow the steps referenced here: Node Manager tutorial
  • Reference: Configure JDBC Data Source
  • Reference: Using RESTful Management Services
  • Create a WebLogic Server domain

    Entity Domain Settings
    Mode Development
    Template

    Oracle Enterprise Manager-Restricted JRF - 12.2.1 [em],
    Oracle Restricted JRF - 12.2.1 [oracle_common],

    WebLogic Coherence Cluster Extension - 12.2.1 [wlserver]

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


  • Open a new Terminal window and start the WebLogic administration server:
/u01/wls1221/user_projects/domains/jrf_domain/bin/startWebLogic.sh
  

When your environment is configured continue with the next topic.

Verify REST Management Services Are Enabled

You must ensure REST management services have been enabled before WebLogic can accept REST requests. Follow these steps to verify this.

  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 if necessary 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 in the /u01 folder and unpackage the files. These files are scripts you can use to execute REST requests against your domain.

    $ tar xvf rest.tar
    $ cd /u01/rest/
    $ ls -l
    answers/
    dep_deployAuction.sh
    dep_list.sh
    dep_undeployAuction.sh
    ds_create.sh
    ds_delete.sh
    ds_getopt.sh
    ds_listAll.sh
    ds_list.sh
    s_listAdmin.sh
    s_listS1.sh
    s_listServers.sh
    s_startS1.sh
    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 localhost port 7001 (#0)
    *   Trying ::1...
    * Connected to localhost (::1) port 7001 (#0)
    * Server auth using Basic with user 'weblogic'
    > GET /management/wls/latest/servers HTTP/1.1
    > Authorization: Basic d2VibG9naWM6d2VsY29tZTE=
    > User-Agent: curl/7.29.0
    > Host: localhost:7001
    > X-Requested-By:MyClient
    > Accept:application/json
    > 
    < HTTP/1.1 200 OK
    < Date: Tue, 22 Sep 2015 23:41:11 GMT
    < Content-Length: 1243
    < Content-Type: application/json
    < Set-Cookie: JSESSIONID=YRn3brIIVcnkLJ3LhDYHF8khRgeavlsXjyVr3d1cI9Wn8_wR4ihw!-1665618047; path=/; HttpOnly
    < 
    {
        "items": [
            {
                "heapFreeCurrent": 669024800,
                "heapSizeCurrent": 948961280,
                "usedPhysicalMemory": 4500873216,
                "jvmProcessorLoad": 1,
                "activeHttpSessionCount": 0,
                "activeThreadCount": 47,
                "health": {"state": "ok"},
                "name": "AdminServer",
                "state": "running"
            },
            {
                "name": "server1",
                "state": "shutdown"
            },
            {
                "name": "server2",
                "state": "shutdown"
            }
        ],
        "links": [
            {
                "rel": "parent",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest"
            },
            {
                "rel": "items.name",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/servers\/id\/AdminServer",
                "title": "AdminServer"
            },
            {
                "rel": "items.name",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/servers\/id\/server1",
                "title": "server1"
            },
            {
                "rel": "items.name",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/servers\/id\/server2",
                "title": "server2"
            }
        ]
    * Connection #0 to host localhost left intact 
  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": 633307008,
            "heapSizeCurrent": 948961280,
            "usedPhysicalMemory": 4507545600,
            "jvmProcessorLoad": 1,
            "activeHttpSessionCount": 0,
            "activeThreadCount": 46,
            "health": {"state": "ok"},
            "name": "AdminServer",
            "state": "running"
        }
    * Connection #0 to host localhost left intact
    
  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 localhost left intact
    
  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.

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

    $ ./s_listS1.sh

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

    {
        "item": {
            "activeHttpSessionCount": 0,
            "activeThreadCount": 39,
            "heapFreeCurrent": 363937008,
            "heapSizeCurrent": 621805568,
            "usedPhysicalMemory": 4532002816,
            "jvmProcessorLoad": 0,
            "health": {"state": "ok"},
            "name": "server1",
            "state": "running"
        },
        "links": [
            {
                "rel": "parent",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/servers"
            },
            {
                "rel": "logs",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/servers\/id\/server1\/logs"
            },
            {
                "rel": "action",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/servers\/id\/server1\/start",
                "title": "start"
            },
            {
                "rel": "action",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/servers\/id\/server1\/restart",
                "title": "restart"
            },
            {
                "rel": "action",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/servers\/id\/server1\/suspend",
                "title": "suspend"
            },
            {
                "rel": "action",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/servers\/id\/server1\/resume",
                "title": "resume"
            },
            {
                "rel": "action",
                "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/servers\/id\/server1\/shutdown",
                "title": "shutdown"
            }
        ]
    * Connection #0 to host localhost left intact
    
  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 localhost left intact
    					* Closing connection #0
  2. View and then execute the following script ( /.ds_getopt.sh) to obtain a Data Source TEMPLATE from WebLogic. 

    $ ./ds_getopt.sh
  3. When you have executed 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. 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. Please note that you must unwrap the items by deleting {"items":... } from your jdbc.options file.

  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 localhost 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": [{
            "jdbcDriverParams": {
                "usePasswordIndirection": false,
                "useXaDataSourceInterface": true,
                "driverName": "oracle.jdbc.OracleDriver",
                "url": "jdbc:oracle:thin:@localhost:1521:orcl",
                "systemProperties": [],
                "properties": [{
                    "name": "user",
                    "value": "system"
                }]
            },
            "aggregateMetrics": {
                "prepStmtCacheAccessCount": 0,
                "prepStmtCacheAddCount": 0,
                "prepStmtCacheDeleteCount": 0,
                "prepStmtCacheCurrentSize": 0,
                "prepStmtCacheHitCount": 0,
                "prepStmtCacheMissCount": 0,
                "currCapacity": 1,
                "numAvailable": 1,
                "highestNumAvailable": 1,
                "numUnavailable": 0,
                "highestNumUnavailable": 1,
                "leakedConnectionCount": 0,
                "failuresToReconnectCount": 0,
                "connectionDelayTime": 3526,
                "activeConnectionsCurrentCount": 0,
                "waitingForConnectionCurrentCount": 0,
                "activeConnectionsHighCount": 1,
                "activeConnectionsAverageCount": 0,
                "reserveRequestCount": 1,
                "failedReserveRequestCount": 0,
                "waitingForConnectionHighCount": 0,
                "waitingForConnectionTotal": 0,
                "waitingForConnectionSuccessTotal": 0,
                "waitingForConnectionFailureTotal": 0,
                "waitSecondsHighCount": 0,
                "connectionsTotalCount": 1,
                "currCapacityHighCount": 1,
                "state": "Running"
            },
            "dataSourceMetrics": [{
                "prepStmtCacheAccessCount": 0,
                "prepStmtCacheAddCount": 0,
                "prepStmtCacheDeleteCount": 0,
                "prepStmtCacheCurrentSize": 0,
                "prepStmtCacheHitCount": 0,
                "prepStmtCacheMissCount": 0,
                "currCapacity": 1,
                "numAvailable": 1,
                "highestNumAvailable": 1,
                "numUnavailable": 0,
                "highestNumUnavailable": 1,
                "leakedConnectionCount": 0,
                "failuresToReconnectCount": 0,
                "connectionDelayTime": 3526,
                "activeConnectionsCurrentCount": 0,
                "waitingForConnectionCurrentCount": 0,
                "activeConnectionsHighCount": 1,
                "activeConnectionsAverageCount": 0,
                "reserveRequestCount": 1,
                "failedReserveRequestCount": 0,
                "waitingForConnectionHighCount": 0,
                "waitingForConnectionTotal": 0,
                "waitingForConnectionSuccessTotal": 0,
                "waitingForConnectionFailureTotal": 0,
                "waitSecondsHighCount": 0,
                "connectionsTotalCount": 1,
                "currCapacityHighCount": 1,
                "serverName": "server1",
                "state": "Running"
            }],
            "jdbcDataSourceParams": {
                "keepConnAfterGlobalTx": false,
                "jndiNames": ["jdbc\/mydatasource-0"],
                "keepConnAfterLocalTx": true,
                "rowPrefetchSize": 48,
                "streamChunkSize": 256,
                "algorithmType": "failover",
                "dataSourceList": null,
                "connectionPoolFailoverCallbackHandler": null,
                "globalTransactionsProtocol": "one phase commit",
                "rowPrefetch": false,
                "failoverRequestIfBusy": false,
                "scope": "global"
            },
            "jdbcConnectionPoolParams": {
                "jdbcXaDebugLevel": 10,
                "testConnectionsOnReserve": false,
                "ignoreInUseConnectionsEnabled": true,
                "removeInfectedConnections": true,
                "credentialMappingEnabled": false,
                "pinnedToThread": false,
                "identityBasedConnectionPoolingEnabled": false,
                "wrapTypes": true,
                "wrapJdbc": true,
                "statementCacheSize": 10,
                "initSql": "",
                "statementCacheType": "least recently used",
                "secondsToTrustAnIdlePoolConnection": 10,
                "statementTimeout": -1,
                "profileType": 0,
                "driverInterceptor": "",
                "fatalErrorCodes": "",
                "connectionLabelingCallback": "",
                "connectionHarvestMaxCount": 1,
                "connectionHarvestTriggerCount": -1,
                "countOfTestFailuresTillFlush": 2,
                "countOfRefreshFailuresTillDisable": 2,
                "initialCapacity": 1,
                "maxCapacity": 15,
                "minCapacity": 1,
                "shrinkFrequencySeconds": 900,
                "highestNumWaiters": 2147483647,
                "connectionCreationRetryFrequencySeconds": 0,
                "connectionReserveTimeoutSeconds": 10,
                "testFrequencySeconds": 120,
                "profileHarvestFrequencySeconds": 300,
                "inactiveConnectionTimeoutSeconds": 0,
                "testTableName": "SQL ISVALID",
                "loginDelaySeconds": 0
            },
            "targets": ["server1"],
            "name": "MyDataSource-0"
        }],
        * Connection #0 to host localhost left intact
    
    
  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 Enterprise Edition 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 localhost 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.

    
    "item": {
            "targets": [{
                "status": "completed",
                "errors": [],
                "name": "AdminServer",
                "type": "server"
            }],
            "beginTime": 1444171381376,
            "endTime": 1444171389191,
            "status": "completed",
            "deploymentName": "SimpleAuctionWebApp",
            "description": "[Deployer:149026]deploy application SimpleAuctionWebApp on AdminServer.",
            "operation": "deploy",
            "name": "ADTR-0",
            "id": "0",
            "type": "deployment"
        },
        "messages": [{
            "message": "Deployed the application 'SimpleAuctionWebApp'.",
            "severity": "SUCCESS"
        }],
        "links": [{
            "rel": "job",
            "uri": "http:\/\/localhost:7001\/management\/wls\/latest\/jobs\/deployment\/id\/0"
        }]
    * Connection #0 to host localhost left intact
    
    
  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": [{
    		"deploymentPath": "\/u01\/rest\/SimpleAuctionWebApp.war",
          		"targets": ["AdminServer"],
    		"name": "SimpleAuctionWebApp",
    		"state": "active",
    		"type": "application",
    		"displayName": "SimpleAuctionWebApp"
    	}]
    * Connection #0 to host localhost 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.

    Confirm Yes, Create Default Data 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.   

    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.

Want to Learn More?

Credits

  • Lead Curriculum Developer: Saskia Niehls
  • Original Oracle by Example tutorial for version 12c created by: Bill Bell
  • Original Oracle by Example tutorial for version 11g created by: TJ Palazzolo
  • Other Contributors: Tom Eliason

Version

  • 01-30-001-ManageWLSREST1221