Jun 29, 2023

Oracle Graph (part 2)

 

Install Graph Client


# create user for the graph client

useradd -g users  -d /home/oragraph -m -s /bin/sh oragraph

echo oragraph | passwd --stdin oragraph

usermod -c 'Usuario para administracion de herramienta graph' oragraph

usermod -s /bin/bash oragraph

usermod -a -G oraclegraph oragraph


# as a oragraph user

# copy oracle-graph-client-<<version>>.zip 

# (donwloaded early from edelivery.oracle.com) to /home/oragraph

unzip oracle-graph-client-<<version>>.zip



# Open grah client

#

# use the java 11 for client works

# (review path /usr/lib/jvm)

export JAVA11_HOME=/usr/lib/jvm/jre-11

# for example

# export JAVA11_HOME=/usr/lib/jvm/jdk-11-oracle-x64

# or use symbolic link:

#export JAVA11_HOME=/usr/lib/jvm/java-11-openjdk-11.0.19.0.7-1.0.1.el7_9.x86_64

cd /home/oragraph/oracle-graph-client-23.2.1/bin

./opg4j --base_url http://localhost:7007 -u ORAGRAPH



# Now you can see the next:

For an introduction type: /help intro

Oracle Graph Server Shell 23.2.1

Variables instance, session, and analyst ready to use.



# Some example commands

opg4j>session

opg4j>instance

opg4j>instance.getPgxUsername()

opg4j>instance.getPgxUserRoles()

opg4j>instance.getPgxGenericPermissions()

opg4j>/help

opg4j>/exit


Install Graph Server and GraphViz on Tomcat (OPTIONAL)


This is a optional installation when you want to use an existing tomcat server.



Prereq: The graph server will work with Apache Tomcat 9.0.x. 


# Create tomcat user

sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcat


 

# install java 8 later using yum or dnf

sudo dnf install openjdk 


# Download tomcat 9 or install using yum

sudo yum install tomcat

sudo yum install tomcat-webapps tomcat-admin-webapps


# In this example we are installing using tar.gz (with a some additional steps)

wget --no-check-certificate  https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.76/bin/apache-tomcat-9.0.76.tar.gz


# Extract and copy software

tar xzf apache-tomcat-9.0.76.tar.gz

sudo mv apache-tomcat-9.0.76/* /opt/tomcat/ 

sudo chown -R tomcat:tomcat /opt/tomcat/ 



# edit and modify ALLOW parameter for enable remote connection for these files:

    Manager -> /opt/tomcat/webapps/manager/META-INF/context.xml

    Host Manager -> /opt/tomcat/webapps/host-manager/META-INF/context.xml   


# Edit both of the above files one by one and add your IP address (like 192.168.1.10) 

<Valve className="org.apache.catalina.valves.RemoteAddrValve"

         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />


# Or instead of  remove/comment the "Valve" Atributtion (using <!-- and --> characters)

<!--  <Valve className="org.apache.catalina.valves.RemoteAddrValve"

         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

-->




# Setup User Accounts and configure password on file:

/opt/tomcat/conf/tomcat-users.xml 


# modify this

<!-- user manager can access only manager section -->

<role rolename="manager-gui" />

<user username="manager" password="oracle" roles="manager-gui" />


<!-- user admin can access manager and admin section both -->

<role rolename="admin-gui" />

<user username="admin" password="oracle" roles="manager-gui,admin-gui" />




# Change default port if you need

vi /opt/tomcat/conf/server.xml

# or in folder $CATALINA_BASE/conf


   <Connector port="9090" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443"

               maxParameterCount="1000"

               />




# Create service with the next content

sudo vi /etc/systemd/system/tomcat.service 





[Unit]

Description=Tomcat 9

After=network.target


[Service]

Type=forking


User=tomcat

Group=tomcat


Environment="JAVA_HOME=/usr/lib/jvm/jre"

Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/opt/tomcat"

Environment="CATALINA_HOME=/opt/tomcat"

Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"

Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"


ExecStart=/opt/tomcat/bin/startup.sh

ExecStop=/opt/tomcat/bin/shutdown.sh


[Install]

WantedBy=multi-user.target



Save the file /etc/systemd/system/tomcat.service  with that content an reload services changes:


# Reload changes

sudo systemctl daemon-reload


# Start tomcat

sudo systemctl enable tomcat.service 

sudo systemctl start tomcat.service 




# Check status from browser

http://localhost:9090 




# now we need deploy the graphviz app from graph app install directory ZIPs # (edelivery.oracle.com) 

oracle-graph-webapps-<version>.zip


# Copy file to weapps folder

# cp graph-server-<version>-pgx<version>.war $CATALINA_HOME/webapps/pgx.war

cp graph-server-23.2.1-pgx23.2.2.war /opt/tomcat/webapps/pxg.war

cp graphviz-23.2.1-tomcat23.2.2.war /opt/tomcat/webapps/graphviz.war

chown tomcat:tomcat /opt/tomcat/webapps/pxg.war

chown tomcat:tomcat /opt/tomcat/webapps/graphviz.war


# Now from start tomcat page http://localhost:9090 

# we need to enter "manager app" and start "pxg" and "graphviz" apps 

# using start button for begin deploy

http://localhost:9090  --> "manager app" 


Deploy option (in this case i have already deployed my graphviz app)



# now it will be listening in

localhost:9090/pgx

localhost:9090/graphviz



# WE need to configure the deployment of PXG

#edit /opt/tomcat/webapps/pxg/WEB-INF/classes/pxg.conf and replace

"jdbc_url": "<REPLACE-WITH-DATABASE-URL-TO-USE-FOR-AUTHENTICATION>",

# With this conent

"jdbc_url": "jdbc:oracle:thin:@localhost:1521/orcl",



# for VIZ change pgx.base_url and jdbc_url parameters for our installation:

/opt/tomcat/webapps/graphviz-23.2.1-tomcat/WEB-INF/web.xml


    <context-param>

        <param-name>pgx.base_url</param-name>

        <param-value>http://localhost:9090/pgx</param-value>

    </context-param>

    <context-param>

        <param-name>graphviz.driver.rdbms.jdbc_url</param-name>

        <param-value>jdbc:oracle:thin:@localhost:1521/orcl</param-value>

    </context-param>


# Replace the next parameters using sed commands

sed -i 's|<secure>true</secure>|<secure>false</secure>|' /opt/tomcat/webapps/graphviz-23.2.1-tomcat/WEB-INF/web.xml

sed -i 's|https://|http://|' /opt/tomcat/webapps/graphviz-23.2.1-tomcat/WEB-INF/web.xml



# Reboot "pxg" and "graphviz" apps from web admin tomcat

http://localhost:9090  --> "manager app" 

# Stop and start button


Oracle Graph (part 1)



In this little lab we are going to install Oracle Graph Server on Standalone machine. You can install Graph on Weblogic and Tomcat if you want also, but this doc is related to standalone installation.


Lets go.

Download Oracle Graph Server


Download from  https://edelivery.oracle.com


In this case i’m going to download 23.2 version.



Select your platform (in my case linux x86-64)


Download the ziip_

  • Oracle Graph Server

  • Oracle Graph Webapps

  • Oracle Graph Client

  • Oracle Graph PL/SQL Path



Installation Graph Server


Some util info:

#DOC link:

https://docs.oracle.com/en/database/oracle//property-graph/23.2/spgdg/oracle-graph-server-and-client-installation.html#GUID-9A53B551-3921-4F62-BAFC-6F371649A827



# URL Lab example

https://apexapps.oracle.com/pls/apex/r/dbpm/livelabs/run-workshop?p210_wid=686&p210_wec=&session=2862275214259





Previous Requirements 


Oracle Linux 7 or 8 x64 or a similar Linux distribution such as RedHat

Oracle JDK 8, JDK 11, or JDK 17 

Due to a bug in Open JDK, it is recommended to avoid the following Oracle JDK versions:

    JDK 11.0.9

    JDK 11.0.10

    JDK 11.0.11

    JDK 11.0.12



NOTE: Every execution command it will be in blue color. The comments about every command it will be with “#” and “--” characters.


Example of java install. Older versions: sudo yum install java-1.8.0-openjdk-devel (root user)

sudo yum install java-11-openjdk-devel



 If you want use opg4p install pyton and pyton devel 3

sudo yum install python3-devel python3 

# Python 3.6 or later

# However, if you want to use Pandas related functionality, you must install Python 3.8 or Python 3.9.

# The install it could be done using PIP:

# pip install --user oracle-graph-client



Configure Database


# From the zip installation (from edelivery.oracle.com)

# run prerequisites script from zip: oracle-graph-plsql-<ver>.zip

# against DB Target

sqlplus "/as sysdba"

ALTER SESSION SET CONTAINER=<YOUR_PDB_NAME>;

@create_graph_roles.sql



# From the same ZIP

# Choose one of the following directories in the optional_pg_schema folder:

# * 18c_and_below: This applies only if you are working with Oracle Database 18c or below.

# * 19c_and_above: This applies only if you are working with Oracle Database 19c or above.

sqlplus "/as sysdba"

ALTER SESSION SET CONTAINER=<YOUR_PDB_NAME>;

@opgremov.sql

@catopg.sql




# Create additional roles and assign to dev and admin roles

set serveroutput on

DECLARE

  PRAGMA AUTONOMOUS_TRANSACTION;

  role_exists EXCEPTION;

  PRAGMA EXCEPTION_INIT(role_exists, -01921);

  TYPE graph_roles_table IS TABLE OF VARCHAR2(50);

  graph_roles graph_roles_table;

BEGIN

  graph_roles := graph_roles_table(

    'GRAPH_DEVELOPER',

    'GRAPH_ADMINISTRATOR',

    'PGX_SESSION_CREATE',

    'PGX_SERVER_GET_INFO',

    'PGX_SERVER_MANAGE',

    'PGX_SESSION_READ_MODEL',

    'PGX_SESSION_MODIFY_MODEL',

    'PGX_SESSION_NEW_GRAPH',

    'PGX_SESSION_GET_PUBLISHED_GRAPH',

    'PGX_SESSION_COMPILE_ALGORITHM',

    'PGX_SESSION_ADD_PUBLISHED_GRAPH');

  FOR elem IN 1 .. graph_roles.count LOOP

  BEGIN

    dbms_output.put_line('create_graph_roles: ' || elem || ': CREATE ROLE ' || graph_roles(elem));

    EXECUTE IMMEDIATE 'CREATE ROLE ' || graph_roles(elem);

  EXCEPTION

    WHEN role_exists THEN

      dbms_output.put_line('create_graph_roles: role already exists. continue');

    WHEN OTHERS THEN

      RAISE;

    END;

  END LOOP;

EXCEPTION

  when others then

    dbms_output.put_line('create_graph_roles: hit error ');

    raise;

END;

/




# Other roles

GRANT PGX_SESSION_CREATE TO GRAPH_ADMINISTRATOR;

GRANT PGX_SERVER_GET_INFO TO GRAPH_ADMINISTRATOR;

GRANT PGX_SERVER_MANAGE TO GRAPH_ADMINISTRATOR;

GRANT PGX_SESSION_CREATE TO GRAPH_DEVELOPER;

GRANT PGX_SESSION_NEW_GRAPH TO GRAPH_DEVELOPER;

GRANT PGX_SESSION_GET_PUBLISHED_GRAPH TO GRAPH_DEVELOPER;

GRANT PGX_SESSION_MODIFY_MODEL TO GRAPH_DEVELOPER;

GRANT PGX_SESSION_READ_MODEL TO GRAPH_DEVELOPER;



# Create graph user for do lab later;

-- Creare graph DB user

Create user ORAGRAPH identified by oracle ;

Alter user ORAGRAPH default Tablespace users;

ALTER USER ORAGRAPH QUOTA unlimited ON USERS ;

GRANT CREATE SESSION, RESOURCE, CREATE TABLE TO ORAGRAPH ;

GRANT ALTER SESSION,CREATE PROCEDURE,CREATE SESSION,CREATE TABLE, CREATE TYPE, CREATE VIEW to ORAGRAPH ; 

GRANT GRAPH_DEVELOPER to ORAGRAPH ;

GRANT GRAPH_ADMINISTRATOR to ORAGRAPH ;

GRANT PGX_SESSION_ADD_PUBLISHED_GRAPH to ORAGRAPH ;


#list of any other privileges maybe you need

https://docs.oracle.com/en/database/oracle//property-graph/23.2/spgdg/oracle-graph-server-and-client-installation.html#GUID-5D2BA510-2DA4-4D64-86BF-A1D8B4734738





Install Graph Server (Standalone option) 


# Check again if exist other graphserver and java version

sudo rpm -q oracle-graph

java -version


# Install graph server

sudo rpm -ivH oracle-graph-<version>.rpm

# Or using:

# sudo yum localinstall  oracle-graph-<version>.rpm


# the lastone command will return this:

Starting post-installation process ...

1. Creating temp directory /opt/oracle/graph/pgx/tmp_data

2. Creating log directory /var/log/oracle/graph

3. Generating demo server keystore ...

Warning: Installation could not generate demo server keystore, keytool is not installed.

Post-installation process completed



#after startup graph and check 

sudo systemctl start pgx

sudo systemctl status pgx



# check errors in :

/var/log/oracle/graph

# In case of start again after fix errors

systemctl reset-failed pgx.service 

systemctl start pgx.service

# In case of review more detail about errors:

# sudo journalctl -u pgx.service 



# Other errors can check in this path:

/var/log/oracle/graph/pgx-server.log


# create user for the graph client

useradd -g users  -d /home/oragraph -m -s /bin/sh oragraph

echo oragraph | passwd --stdin oragraph

usermod -c 'Usuario para administracion de herramienta graph' oragraph

usermod -s /bin/bash oragraph

usermod -a -G oraclegraph oragraph



# As oragrahp osuser, configure the server by modifying the files 

# under /etc/oracle/graph by following the steps under

# Prepare the Graph Server for Database Authentication.

# More detail:

# https://docs.oracle.com/en/database/oracle//property-graph/23.2/spgdg/oracle-graph-server-and-client-installation.html#GUID-03010F75-088C-4D6C-860A-D040597B2CF5




edit /etc/oracle/graph/pgx.conf and replace

"jdbc_url": "<REPLACE-WITH-DATABASE-URL-TO-USE-FOR-AUTHENTICATION>",


With this content or your respective URL (in my case is this string)

"jdbc_url": "jdbc:oracle:thin:@localhost:1521/orcl",


# open  /etc/oracle/graph/server.conf and edit

"enable_tls": false


# In  /etc/oracle/graph/server.conf you can edit the port also  (default 7007)

"port": 7007,



# Edit the graphviz app for avoid errors LOGGED from web browser

# GraphViz

WAR=$(find /opt/oracle/graph/graphviz -name '*.war')

TMP=$(mktemp -d)

cd $TMP

unzip $WAR WEB-INF/web.xml

sed -i 's|<secure>true</secure>|<secure>false</secure>|' WEB-INF/web.xml

sed -i 's|https://|http://|' WEB-INF/web.xml

sudo zip $WAR WEB-INF/web.xml

chown root:oraclegraph $WAR

rm -r $TMP


# restart graphserver

sudo systemctl restart pgx

sudo systemctl status pgx


With These changes you have right now working:

Graphserver running on http://localhost:7007/

GraphVizualitation running on http://localhost:7007/ui

(this last option we will working with a little lab chapter later)