Friday, December 28, 2012

Python class : getting started

I have never done any OO in Python, but I think I should. OO is good.
Maybe one day will shall say "there was a time where people believed in OO, hahaha what a bunch of losers, now we know that the right thing to do is.... (name your methodology)".

But in the meantime OO is better than Hashtables.

Minimalistic class:
class Pippo:
    name = "hello"


Unlike in Java, this doesn't work:
class Pippo:


there MUST be something inside a class.

Now you can do:
a = Pippo()

this is valid because Pippo has been defined.... if you do
a = Peppo()
you get an error because Peppo class is not defined.

If you do:
a = Pippo()
print a.name
hello

as expected, name was initialized and it's a Object variable, not a Class variable (I mean, it's not static):

a = Pippo()
b = Pippo()
a.name ="bla"
b.name = "mumble"

print a.name
bla
print b.name
mumble

Now let's do:
a.name = "ciao"
a.surname = "bello"
print a


print a.name
ciao

print a.surname
bello

so it's not necessary to declare a member of a class in order to use it. I don't like it, very error prone. I am VERY much in favor of VERY strict syntax.


So it's a MUCH better approach to use mainly Constructors to assign values to attributes:



class Pippo:
    def __init__(self, name, surname):
        self.name = name
        self.surname = surname


a = Pippo("alfa", "beta")

print a.name
alfa
print a.surname
beta


now you can define your classes in a module myclasses.py and then do:

from myclasses import Pippo




iTunes, worse than ever

I was hoping that, after the death of Steve Jobs (god bless his soul), the design of the iTunes software would go back to some more reasonable, humanly acceptable UI standard.

It turns out that his latest release is even more counter-intuitive, freaky and obnoxious than past ones - which I thought were already breaking all records of poor design.

Forget the poverty of the iPhone device: iTunes alone is a very good reason to steer clear from Apple products.

If I had a trading account I would short AAPL.

I had been warned not to buy iPhone, and rather buy Android.... ah if only I listened to other people advice ....

Thursday, December 27, 2012

more Puppet

previous post with videos here. http://www.javamonamour.org/2012/06/puppet-labs.html



Learning Puppet: http://docs.puppetlabs.com/learning/

First steps here: http://docs.puppetlabs.com/learning/agentprep.html

Download the VM : http://info.puppetlabs.com/download-learning-puppet-VM.html and you get a file learn_puppet_centos_pe2.5.1_vmx.2012.04.18.zip


  1. Puppet open source downloads
  2. Comprehensive Puppet installation guide
  3. A step-by-step guide to learning Puppet
  4. The Puppet 3 Reference Manual



  1. Download Puppet: If you haven't already downloaded Puppet, get your free download now and access the latest versions of Puppet, Facter, and MCollective.

  2. Install Puppet: Review the Installing Puppet Documentation to install and configure the latest Puppet open source releases.

  3. Get Schooled: We have an extensive collection of resources to guide you through using Puppet. Here are a few to help you get started:




Tuesday, December 25, 2012

WebLogic 11 Log Message Format

In Java, I can rename a thread:

String originalName = Thread.currentThread().getName();
Thread.currentThread().setName(originalName + " - My custom name here");



Here the WebLogic 11 Log Format doc

For example this is an error message:

####<Dec 18, 2012 11:55:29 AM CET> <Error> <ALSB Logging> <acme108> <osbpr1ms2> <[ACTIVE] ExecuteThread: '23' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <465bebdd30aa6335:1ab575e0:13b48cc30e9:-8000-00000000007651df> <1355828129705> <BEA-000000> < [null, null, null, ERROR] ****CheckMachineExists_PS - Fault in SEH****: con:fault xmlns:con="http://www.bea.com/wli/sb/context"

this is:

Locale-formatted Timestamp <Dec 18, 2012 11:55:29 AM CET>
Severity <Error>
Subsystem <ALSB Logging>
Machine Name <acme108>
Server Name <osbpr1ms2>
Thread ID <[ACTIVE] ExecuteThread: '23' for queue: 'weblogic.kernel.Default (self-tuning)'>
User ID <<anonymous>>
Transaction ID <>
Diagnostic Context ID <465bebdd30aa6335:1ab575e0:13b48cc30e9:-8000-00000000007651df>
Raw Time Value <1355828129705>
Message ID <BEA-000000>
Message Text < [null, null, null, ERROR] ****CheckMachineExists_PS - Fault in SEH****: con:fault xmlns:con="http://www.bea.com/wli/sb/context"


Here some explanation on what a Diagnostic Context ID is.



Monday, December 24, 2012

Very useful Oracle DB queries

show all tablespaces used in this DB:

select unique TABLESPACE_NAME from DBA_TABLES;


show all indexes on a table:

SELECT i.index_name, ic.column_position, ic.column_name
FROM user_indexes i JOIN user_ind_columns ic
ON i.index_name = ic.index_name
WHERE i.TABLE_NAME = 'MYTABLE';




select * from V$DATABASE,

and

select * from GV$INSTANCE;

tell you a lot about SID, SERVICE_NAME and other properties of your instance.



Saturday, December 22, 2012

Book of the month: The Cultures of Native North Americans

This is an incredibly beautiful book - at a really discount price on Amazon - on a wonderful world of a myriad of different civilizations exterminated in the impact with the most virulent species on the planet: the white European.



(original title Kulturen der nordamerikanischen Indianer )

A testimony on what once was the most beautiful planet of the Universe, and that has been wiped out in a space of a few centuries.

Friday, December 21, 2012

A special message for a special person


If you want to tell a colleague how great he/she is, here is a template you can reuse:



We want to tell you that……





There are times when work was like this

Or Like this!!
 


But then you are always there like this
 
 So we all wanted to say that


Also there are times when


 So next time you are here you MUST
 With lots of


And finally we all wanted to tell you
For being such






Wednesday, December 19, 2012

Oracle Client installation on Windows

Download the client here: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-win32soft-098987.html

The file is win32_11gR2_client.zip.

I run install the setup ad Administrator - otherwise it fails to assess the prerequisites - and I specify as installation directory C:\pierre\oradb\product\11.2.0\client_1

I also do custom installation and choose "Oracle Database Utilities"




This will surely install also exp and imp export utilities.

Once installation is done, I go to C:\pierre\oradb\product\11.2.0\client_1\network\admin
and AS ADMINISTRATOR I create a tnsname.ora file with this content (be careful about spaces etc):


PIPPO_PPRD =(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dmhost.acme.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=srv_osb)))

To test, I go to C:\pierre\oradb\product\11.2.0\client_1\bin and run:

exp help=y
the BUFFERS parameter is very important for performance
Make sure you define
PATH=C:\pierre\oradb\product\11.2.0\client_1\bin;C:\pierre\oradb\product\11.2.0\client_1\

I have also set
set TNS_ADMIN=%PATH%;C:\pierre\oradb\product\11.2.0\client_1\network\admin
but I am not sure if it's required

This command should work:

exp pp1_soainfra/pp1_peppo@PIPPO_PPRD TABLES=PIPPO_FTP SERVERS file=c:\pierre\myexport.exp log=c:\pierre\mylog.log STATISTICS=NONE

if not, check the TNSNAMES.ORA with this command:

tnsping PIPPO_PPRD

TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 19-DEC-2012 16:02:39

Copyright (c) 1997, 2010, Oracle.  All rights reserved.

Used parameter files:
c:\pierre\oradb\product\11.2.0\client_1\network\admin\sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dmhost.acme.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=srv_osb)))

OK (50 msec)


BEA-110486: cannot complete commit processing

Full message is:
Transaction BEA1-3028024724CE1F5F1C3A cannot complete commit processing because 
resource [WLStore_osbpr1do_CommonFileStore1] is unavailable. The transaction will be abandoned after 84,775 seconds unless all resources acknowledge the commit decision.

Googling in Oracle Forum I find this recipe to use if the above error prevents your server from starting:
1. Stop your server.
2. Go to [your domain]\servers\AdminServer\data\store\default.
3. Delete* _WLS_ADMINSERVER_[random number].DAT
4. Restart server



Sunday, December 16, 2012

Splunk pretrained data sources: weblogic_stdout

When you add new data, make sure you choose "manual" datasource type, and enter manually "weblogic_stdout" . I personally thing this was a very bad UI design decision.... ALWAYS explicitly display all the available choices in a UI, NOTHING should be entered manually.



see http://docs.splunk.com/Documentation/Splunk/latest/Data/Listofpretrainedsourcetypes

cd $SPLUNK_HOME/bin
./splunk btool props list weblogic_stdout


[weblogic_stdout]
ANNOTATE_PUNCT = True
BREAK_ONLY_BEFORE = ^####
BREAK_ONLY_BEFORE_DATE = True
CHARSET = UTF-8
DATETIME_CONFIG = /etc/datetime.xml
HEADER_MODE =
KV_MODE = none
LEARN_SOURCETYPE = true
LINE_BREAKER_LOOKBEHIND = 100
MAX_DAYS_AGO = 2000
MAX_DAYS_HENCE = 2
MAX_DIFF_SECS_AGO = 3600
MAX_DIFF_SECS_HENCE = 604800
MAX_EVENTS = 2048
MAX_TIMESTAMP_LOOKAHEAD = 32
MUST_BREAK_AFTER =
MUST_NOT_BREAK_AFTER =
MUST_NOT_BREAK_BEFORE =
REPORT-st = weblogic-code
REPORT-weblogic92 = wl-log-fields, wl-log-thread-fields
SEGMENTATION = indexing
SEGMENTATION-all = full
SEGMENTATION-inner = inner
SEGMENTATION-outer = outer
SEGMENTATION-raw = none
SEGMENTATION-standard = standard
SHOULD_LINEMERGE = True
TRANSFORMS =
TRUNCATE = 10000
maxDist = 60





Book: Seeds of Deception

The book is a bot old, but still a very startling and inconvenient reading about the way Corporations and their political servants are working hard to enslave and kill us all.



Seed expert and activist Vandana Shiva gives an extensive presentation on this topic



More on the Monsanto topic in this excellent documentary:





Saturday, December 15, 2012

Splunk and WebLogic

Tired of grepping like a monkey? Use SPLUNK

The tutorial videos on their home page are excellent.

for managed server logs:

http://splunkbase.splunk.com/apps/All/3.x/app:WebLogic+Event+Types#


for access logs:

http://splunkbase.splunk.com/apps/All/3.x/app:WebLogic+Access




The tutorial video on installing Splunk on Linux is here  (you must create an account).
Downloaded splunk-5.0.1-143156-Linux-x86_64.gz . Put in /opt2, tar xvf splunk-5.0.1-143156-Linux-x86_64.gz,
cd /opt2/splunk/
./splunk start

log into http://myserver.com:8000/en-GB/account/login?return_to=%2Fen-GB%2F as admin / changeme
change password
add data, A file or directory of files, Consume any file on this Splunk server, select a weblogic file
the choices available are:


    A file or directory of files
    Syslog
    Windows event logs
    Windows Registry
    Windows performance metrics

    Unix/Linux logs and metrics
    File integrity monitoring
    Configuration files
    OPSEC LEA
    Cisco device logs

    llS logs
    Apache logs
    WebSphere logs, metrics and other data
    Any other data...

Out of the box, the WebLogic files are not recognized
You can read the book Exploring Splunk at http://www.splunk.com/web_assets/v5/book/Exploring_Splunk.pdf

To install the WebLogic Eventy Type app:
http://docs.splunk.com/Documentation/Splunk/3.4.13/Admin/InstallSplunkApplications

the menu is: splunk, Manager, Apps, Upload App, and provide the weblogic.tar.gz downloaded from the link http://splunkbase.splunk.com/apps/All/3.x/app:WebLogic+Event+Types#

Cool video on how to add a directory of files for indexing:



grepping the smart way

Unfortunately WebLogic prints each log entry in multiple lines. This is a pain when you grep.

gawk will return the whole log entry:

gawk "BEGIN{RS=\"####\"}/BEA-000337/{print \$0}" *.log


When using grep, the option -A4 is handy to print a few extra lines (in the example, 4) after the ling matching the pattern:

grep -A4 BEA-000337 *





WebLogic WLDF incidents notified by email

Open WebLogic console

Services / Mail Sessions / new Mail Sessions

MailSessionAdmin : JavaMail Properties: mail.smtp.host=smtp.acme.com

here the full list of the JavaMail Properties


Diagnostic Modules - Module-FMWDFW - Watches and Notifications - Notifications - FMWDFWNotification; Type = SMTP (E-Mail)

SMTP Properties ; Mail Session Name = MailSessionAdmin

E-Mail Recipients = pvernetto@gmail.com

To test, prepare a exceptionGenerator.jsp containing:

<% throw new NullPointerException("hello"); %>
Deploy the JSP in a TestWebApp war to the WLS,
http://myserver.acme.com:7001/TestWebApp/exceptionGenerator.jsp
you should get this:

 at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
 at
 weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)

 at
 weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)

 at
 weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)

 at
 weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:416)

 at
 weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:326)

 at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
 at
 weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)

 at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)

 at java.security.AccessController.doPrivileged(Native Method)
 at
 oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
 at
 oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)

 at
 oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)

 at
 oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)

 at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
 at
 weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)

 at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)

 at
 weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)

 at
 weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)

 at
 weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)

 at
 weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)

 at
 weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)

 at
 weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)

 at
 weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)

 at
 weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)

 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
 at
 weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
 SUBSYSTEM = HTTP
 USERID =  SEVERITY = Error THREAD = [ACTIVE] ExecuteThread: '3'
 for queue: 'weblogic.kernel.Default (self-tuning)' MSGID = BEA-101020  MACHINE = myserver TXID =  CONTEXTID =
 11d1def534ea1be0:65fd0c39:13b9bd510e7:-8000-00000000000001f7 TIMESTAMP =
 1355556858627
WatchAlarmType: AutomaticReset
WatchAlarmResetPeriod:
 30000
SMTPNotificationName: FMWDFWNotification
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

WatchTime: Dec 15, 2012 8:34:18 AM CET
WatchDomainName: osbpl1do
WatchServerName: osbpl1as
WatchSeverityLevel: Notice
WatchName: UncheckedException
WatchRuleType: Log
WatchRule: (SEVERITY = 'Error') AND ((MSGID = 'WL-101020') OR (MSGID = 'WL-101017') OR (MSGID = 'WL-000802') OR (MSGID = 'BEA-101020') OR (MSGID = 'BEA-101017') OR (MSGID = 'BEA-000802'))
WatchData: DATE = Dec 15, 2012 8:34:18 AM CET SERVER = osbpl1as MESSAGE = [ServletContext@453292093[app:TestWebApp module:TestWebApp.war path:/TestWebApp spec-version:2.5]] Servlet failed with Exception
java.lang.NullPointerException: hello
 at jsp_servlet.__exceptiongenerator._jspService(__exceptiongenerator.java:71)
 at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
 at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
 at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
 at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
 at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:416)
 at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:326)
 at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
 at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
 at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
 at java.security.AccessController.doPrivileged(Native Method)
 at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
 at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
 at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
 at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
 at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
 at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
 at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
 at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
 at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
 at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
 at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
 at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
 at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
 at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
 at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
 at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
 SUBSYSTEM = HTTP USERID =  SEVERITY = Error THREAD = [ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)' MSGID = BEA-101020 MACHINE = myserver TXID =  CONTEXTID = 11d1def534ea1be0:65fd0c39:13b9bd510e7:-8000-00000000000001f7 TIMESTAMP = 1355556858627
WatchAlarmType: AutomaticReset
WatchAlarmResetPeriod: 30000
SMTPNotificationName: FMWDFWNotification 







WebLogic Request Performance

A great demo from Jambay:


and here is the official Oracle documentation

By default you have a Diagnostic Module Module-FMWDFW containing whese watches:

UncheckedException = (SEVERITY = 'Error') AND ((MSGID = 'WL-101020') OR (MSGID = 'WL-101017') OR (MSGID = 'WL-000802') OR (MSGID = 'BEA-101020') OR (MSGID = 'BEA-101017') OR (MSGID = 'BEA-000802'))

Deadlock=((SEVERITY = 'Critical') OR (SEVERITY = 'Info')) AND ((MSGID = 'WL-000394') OR (MSGID = 'BEA-000394'))

StuckThread=(SEVERITY = 'Error') AND ((MSGID = 'WL-000337') OR (MSGID = 'BEA-000337'))



Thursday, December 13, 2012

XAER_RMFAIL : Resource manager is unavailable


Could not invoke operation 'CheckMachineExist' due to:

BINDING.JCA-11812
Interaction processing error.
Error while processing the execution of the CONFIGDB.CHECKMACHINEEXISTS API interaction.
An error occurred while processing the interaction for invoking the CONFIGDB.CHECKMACHINEEXISTS API. Cause: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Unexpected exception while enlisting XAConnection java.sql.SQLException: XA error: XAResource.XAER_RMFAIL start() failed on resource 'PIPPO_osbpr1do': XAER_RMFAIL : Resource manager is unavailable
oracle.jdbc.xa.OracleXAException
        at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1616)
        at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:336)
        at weblogic.jdbc.wrapper.VendorXAResource.start(VendorXAResource.java:50)
        at weblogic.jdbc.jta.DataSource.start(DataSource.java:729)
        at weblogic.transaction.internal.XAServerResourceInfo.start(XAServerResourceInfo.java:1231)
        at weblogic.transaction.internal.XAServerResourceInfo.xaStart(XAServerResourceInfo.java:1164)
        at weblogic.transaction.internal.XAServerResourceInfo.enlist(XAServerResourceInfo.java:285)
        at weblogic.transaction.internal.ServerTransactionImpl.enlistResource(ServerTransactionImpl.java:522)
        at weblogic.transaction.internal.ServerTransactionImpl.enlistResource(ServerTransactionImpl.java:449)
        at weblogic.jdbc.jta.DataSource.enlist(DataSource.java:1599)
        at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist(DataSource.java:1503)
        at weblogic.jdbc.jta.DataSource.getConnection(DataSource.java:446)
        at weblogic.jdbc.jta.DataSource.connect(DataSource.java:403)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:364)
       at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:126)




This might well be because your Oracle DB has hit the maximum number of processes.

select count(*) from v$process;

show parameter session

NAME                                               TYPE        VALUE                                                                                                
-------------------------------------------------- ----------- ---------------------------------------------------------------------------------------------------- 
java_max_sessionspace_size                         integer     0                                                                                                    
java_soft_sessionspace_limit                       integer     0                                                                                                    
license_max_sessions                               integer     0                                                                                                    
license_sessions_warning                           integer     0                                                                                                    
session_cached_cursors                             integer     50                                                                                                   
session_max_open_files                             integer     10                                                                                                   
sessions                                           integer     480                                                                                                  
shared_server_sessions                             integer                                                                                                          


show parameter processes


-------------------------------------------------- ----------- ---------------------------------------------------------------------------------------------------- 
NAME                                               TYPE        VALUE                                                                                                
-------------------------------------------------- ----------- ---------------------------------------------------------------------------------------------------- 
aq_tm_processes                                    integer     1                                                                                                    
db_writer_processes                                integer     1                                                                                                    
gcs_server_processes                               integer     2                                                                                                    
global_txn_processes                               integer     1                                                                                                    
job_queue_processes                                integer     1000                                                                                                 
log_archive_max_processes                          integer     4                                                                                                    
processes                                          integer     300  


You can change it with
alter system set processes=300 scope=spfile;


Sunday, December 9, 2012

Shell script, redirecting a script's output in a simple way

This is really the simplest way I could find: just embed the redirection thing in the script itself, live happily ever after.



main_function() {
        echo Ciao
        echo Miao
}



main_function > pippo.log 2>&1



If you want to see the output while executing:
LOG_FILE=bla.log
main_function | tee -a $LOG_FILE 2>&1


Friday, December 7, 2012

Woodstock 1969

Joe Cocker (super!)



Canned Heat (really cool):




Santana, soul sacrifice (I don't like it)


Richie Havens (very boring)



Arlo Guthrie (ok):



NEXT STOP IS VIET NAM (great!)



The Who



Jefferson Airplane



Janis Joplin (the unforgettable, gone too soon)





Thursday, December 6, 2012

OSB-SFTP with FtpAdapter

http://docs.oracle.com/cd/E23943_01/integration.1111/e10231/adptr_file.htm#CACDFFFB

http://myexperienceswithsoa.blogspot.ch/2011/04/using-sftp-with-oracle-soa.html

http://erikwramner.wordpress.com/2010/02/15/configuring-the-oracle-ftp-adapter-for-sftp-with-ssh-dsa/




On Linux, sftp server runs on
/usr/libexec/openssh/sftp-server

man sftp-server is http://www.manpagez.com/man/8/sftp-server/

By default it logs only errors, and it runs on port 22
On Linux you must be root to change the log level or the port number (sftp-config)
Logs are in
less /var/log/messages
less /var/log/secure
Here http://www.cerberusftp.com/download/downloadnow.html download an excellent SFTP server for Windows. You should create a user with rename, delete, create directories privileges.


this is a typical session:


2012/12/06 12:28:00     [1]     Incoming connection request on SSH interface 2 at 10.240.11.111
2012/12/06 12:28:00     [1]     SSH FTP connection request accepted from 10.56.5.165
2012/12/06 12:28:00     [1]     Client Identification: SSH-2.0-J2SSH_Maverick_1.2.6_Oracle Corporation
2012/12/06 12:28:00     [1]     Algorithm negotiation complete: Proceeding with key exchange
2012/12/06 12:28:00     [1]     Kex: 'diffie-hellman-group1-sha1' Host Key: 'ssh-rsa' C2S : 'aes128-cbc, hmac-md5, none' S2C : 'aes128-cbc, hmac-md5, none'
2012/12/06 12:28:01     [1]     DH Key sizes: Server Public '1023', Private '1023', Client Public '1023'
2012/12/06 12:28:01     [1]     Authenticating password for user 'soa'
2012/12/06 12:28:01     [1]     Native user 'soa' authenticated
2012/12/06 12:28:01     [1]     Channel Open: 'session', Sender Channel: 0, Init Window Size: 131070, Max Packet Size: 34000
2012/12/06 12:28:01     [1]     Creating local channel: 32
2012/12/06 12:28:01     [1]     Channel Request: 'subsystem', Recipient Channel: 32, Subsystem Name: 'sftp', Reply: true
2012/12/06 12:28:01     [1]     Client SFTP version: 4
2012/12/06 12:28:01     [1]     Real Path for '.'
2012/12/06 12:28:01     [1]     Stat: /home/soa/pippo/environments/env-0/ave/tmp
2012/12/06 12:28:01     [1]     Request to close channel '32'
2012/12/06 12:28:01     [1]     Channel '32' removed
2012/12/06 12:28:11     [1]     Disconnect reason: The user disconnected the application
2012/12/06 12:28:11     [1]     The client closed the connection
2012/12/06 12:28:11     [1]     Connection terminated
2012/12/06 12:28:31     [2]     Incoming connection request on SSH interface 2 at 10.240.21.111
2012/12/06 12:28:31     [2]     SSH FTP connection request accepted from 10.56.5.165
2012/12/06 12:28:31     [2]     Client Identification: SSH-2.0-J2SSH_Maverick_1.2.6_Oracle Corporation
2012/12/06 12:28:31     [2]     Algorithm negotiation complete: Proceeding with key exchange
2012/12/06 12:28:31     [2]     Kex: 'diffie-hellman-group1-sha1' Host Key: 'ssh-rsa' C2S : 'aes128-cbc, hmac-md5, none' S2C : 'aes128-cbc, hmac-md5, none'
2012/12/06 12:28:31     [2]     DH Key sizes: Server Public '1023', Private '1023', Client Public '1024'
2012/12/06 12:28:31     [2]     Authenticating password for user 'soa'
2012/12/06 12:28:31     [2]     Native user 'soa' authenticated
2012/12/06 12:28:31     [2]     Channel Open: 'session', Sender Channel: 0, Init Window Size: 131070, Max Packet Size: 34000
2012/12/06 12:28:31     [2]     Creating local channel: 48
2012/12/06 12:28:31     [2]     Channel Request: 'subsystem', Recipient Channel: 48, Subsystem Name: 'sftp', Reply: true
2012/12/06 12:28:31     [2]     Client SFTP version: 4
2012/12/06 12:28:31     [2]     Real Path for '.'
2012/12/06 12:28:31     [2]     Stat: /home/soa/pippo/environments/env-0/ave/tmp
2012/12/06 12:28:31     [2]     Request to close channel '48'
2012/12/06 12:28:31     [2]     Channel '48' removed



Oracle Database requirements for a OSB domain

This is the official documentation:
http://docs.oracle.com/html/E18558_01/fusion_requirements.htm#BABFDFDD , section "RCU Requirements for Oracle Databases"

and we need only these components:
SOA Infrastructure
User Messaging Server (ORASDPM)
Metadata Services (MDS)


which entails these requirements:

- processes: 200
- Character set is AL32UTF8.
- The SHARED_POOL_SIZE is greater than or equal to 147456KB.
- The SGA_MAX_SIZE is greater than or equal to 147456KB.
- The DB_BLOCK_SIZE is greater than or equal to 8KB




Oracle DB, generating sample data

useful commands:

INSERT INTO TEXTTEST (TEXTCOLUMN, NUMBERCOLUMN) SELECT DBMS_RANDOM.STRING('A',10), TRUNC(DBMS_RANDOM.VALUE(1111111111,9999999999)) FROM DUAL CONNECT BY LEVEL <=250000;




Tuesday, December 4, 2012

WLST to apply a log filter

Creating a log Filter is not enough, you should also associate it to each managed server and admin server:

startEdit()
cd('/')
cmo.createLogFilter('LogFilter-1')

cd('/LogFilters/LogFilter-1')
cmo.setFilterExpression('NOT(MSGID = \'BEA-149515\')')


cd('/Servers/myms1/Log/myms1')
cmo.setLogFileFilter(getMBean('/LogFilters/LogFilter-1'))
cmo.setStdoutFilter(getMBean('/LogFilters/LogFilter-1'))
cmo.setDomainLogBroadcastFilter(getMBean('/LogFilters/LogFilter-1'))

activate()



Monday, December 3, 2012

oracle DB, which user privileges do I have?

select * from SESSION_PRIVS;

CREATE SESSION
CREATE TABLE
CREATE VIEW
CREATE SEQUENCE
CREATE PROCEDURE
CREATE MATERIALIZED VIEW
CREATE TYPE
MANAGE ANY QUEUE
ENQUEUE ANY QUEUE
DEQUEUE ANY QUEUE
CREATE EVALUATION CONTEXT
CREATE RULE SET
CREATE RULE
CREATE JOB



To assign a privilege to user PIPPO:

GRANT CREATE JOB to PIPPO;

see also

http://docs.oracle.com/cd/B10500_01/server.920/a96521/privs.htm




Saturday, December 1, 2012

Cloning a DB table and renaming

create table PIPPO as (select * from PLUTO where 1 = 2);

this will create an empty table.

Unfortunately, neither PK nor FKs nor indexes will be created.

The not null constraints WILL be created.

rename PIPPO to PLUTO;

will change the table name. Be careful because all the old indexes associated to PIPPO will now be associated to PLUTO, so you might have to rename also indexes.







Wednesday, November 28, 2012

OPatch

/opt/oracle/fmw11_1_1_5/oracle_common/OPatch/opatch lsinventory

OPatch cannot find a valid oraInst.loc file to locate Central Inventory.


/opt/oracle/fmw11_1_1_5/oracle_common/OPatch/opatch lsinventory -invPtrLoc /opt/oracle/fmw11_1_1_5/oraInst.loc

Invoking OPatch 11.1.0.8.2

Oracle Interim Patch Installer version 11.1.0.8.2
Copyright (c) 2010, Oracle Corporation.  All rights reserved.


Oracle Home       : /opt/oracle/fmw11_1_1_5/oracle_common
Central Inventory : /opt/oracle/orainventory
   from           : /opt/oracle/fmw11_1_1_5/oraInst.loc
OPatch version    : 11.1.0.8.2
OUI version       : 11.1.0.9.0
OUI location      : /opt/oracle/fmw11_1_1_5/oracle_common/oui
Log file location : /opt/oracle/fmw11_1_1_5/oracle_common/cfgtoollogs/opatch/opatch2012-11-28_18-58-45PM.log

Patch history file: /opt/oracle/fmw11_1_1_5/oracle_common/cfgtoollogs/opatch/opatch_history.txt


OPatch detects the Middleware Home as "/opt/oracle/fmw11_1_1_5"

Lsinventory Output file location : /opt/oracle/fmw11_1_1_5/oracle_common/cfgtoollogs/opatch/lsinv/lsinventory2012-11-28_18-58-45PM.txt

--------------------------------------------------------------------------------
Installed Top-level Products (1):

Oracle AS Common Toplevel Component                                  11.1.1.2.0
There are 1 products installed in this Oracle Home.


There are no Interim patches installed in this Oracle Home.


--------------------------------------------------------------------------------

OPatch succeeded.








export MW_HOME=/opt/oracle/fmw11_1_1_5/
export ORACLE_HOME=/opt/oracle/fmw11_1_1_5/osb
export JDK_HOME=/opt/oracle/java

/opt/oracle/fmw11_1_1_5/oracle_common/OPatch/opatch apply -jdk /opt/oracle/java/ -invPtrLoc /opt/oracle/fmw11_1_1_5/oraInst.loc
Invoking OPatch 11.1.0.8.2

Oracle Interim Patch Installer version 11.1.0.8.2
Copyright (c) 2010, Oracle Corporation.  All rights reserved.


Oracle Home       : /opt/oracle/fmw11_1_1_5/osb
Central Inventory : /opt/oracle/orainventory
   from           : /opt/oracle/fmw11_1_1_5/oraInst.loc
OPatch version    : 11.1.0.8.2
OUI version       : 11.1.0.9.0
OUI location      : /opt/oracle/fmw11_1_1_5/osb/oui
Log file location : /opt/oracle/fmw11_1_1_5/osb/cfgtoollogs/opatch/opatch2012-11-28_19-23-38PM.log

Patch history file: /opt/oracle/fmw11_1_1_5/osb/cfgtoollogs/opatch/opatch_history.txt


OPatch detects the Middleware Home as "/opt/oracle/fmw11_1_1_5"

ApplySession applying interim patch '12747853' to OH '/opt/oracle/fmw11_1_1_5/osb'

Running prerequisite checks...

OPatch detected non-cluster Oracle Home from the inventory and will patch the local system only.


Please shutdown Oracle instances running out of this ORACLE_HOME on the local system.
(Oracle Home = '/opt/oracle/fmw11_1_1_5/osb')


Is the local system ready for patching? [y|n]
y
User Responded with: Y
Backing up files and inventory (not for auto-rollback) for the Oracle Home
Backing up files affected by the patch '12747853' for restore. This might take a while...
Backing up files affected by the patch '12747853' for rollback. This might take a while...

Patching component oracle.osb.top, 11.1.1.5.0...
Updating jar file "/opt/oracle/fmw11_1_1_5/osb/lib/transports/jcatransport.ear" with "/lib/transports/jcatransport.ear/APP-INF/lib/jcatransport.jar/com/bea/wli/sb/transports/jca/JCATransportAppListener.class"
Updating jar file "/opt/oracle/fmw11_1_1_5/osb/lib/transports/jcatransport.jar" with "/lib/transports/jcatransport.jar/com/bea/wli/sb/transports/jca/JCATransportAppListener.class"
ApplySession adding interim patch '12747853' to inventory

Verifying the update...
Inventory check OK: Patch ID 12747853 is registered in Oracle Home inventory with proper meta-data.
Files check OK: Files from Patch ID 12747853 are present in Oracle Home.

The local system has been patched and can be restarted.



Tuesday, November 27, 2012

Trying to teach myself security


Read in this order:

http://en.wikipedia.org/wiki/Digital_signature

http://en.wikipedia.org/wiki/Public-key_encryption

http://en.wikipedia.org/wiki/Public_key

http://en.wikipedia.org/wiki/RSA_%28algorithm%29
http://en.wikipedia.org/wiki/Digital_Signature_Algorithm
http://en.wikipedia.org/wiki/Advanced_Encryption_Standard

http://en.wikipedia.org/wiki/Symmetric-key_algorithm




http://en.wikipedia.org/wiki/Public_key_certificate






Monday, November 26, 2012

PL/SQL to transfer files in small chunks

When confronted to copying large amounts of data in a DB, normally you don't want to do it in a mammoth transaction, since this could severely damage running application, and even fill your redo logs.

This is a sample anonymous block to run the transfer in small chunks (in the example, 7 days worth of data are transferred at 600 seconds blocks)


declare v_now  date;
v_delay_in_seconds number;

begin 

v_now := sysdate;

for thedelay in reverse 1.. 7 * 24 * 6 loop
  v_delay_in_seconds := thedelay * 600;

  insert into WLI_REPORTING_ARCHIVE
(
   MSG_GUID, HOST_NAME, MSG_LABELS, ERRORCODE, ERRORDESCRIPTION,  
 INTERFACEID, BUSINESSID, BUSINESSUNIQUEID, EVENTTYPE, 
 EVENTOCCUREDON, TECHNICALMESSAGEID, PATHOFSERVICE, 
 FILENAME, ISERROR, EVENTOCCUREDON_EPOCH, DB_TIMESTAMP, DATA_VALUE
)
select A.MSG_GUID, A.HOST_NAME, A.MSG_LABELS, A.ERRORCODE, A.ERRORDESCRIPTION,  
 A.INTERFACEID, A.BUSINESSID, A.BUSINESSUNIQUEID, A.EVENTTYPE, 
 A.EVENTOCCUREDON, A.TECHNICALMESSAGEID, A.PATHOFSERVICE, 
 A.FILENAME, A.ISERROR, A.EVENTOCCUREDON_EPOCH, A.DB_TIMESTAMP, c.data_value 
from WLI_QS_REPORT_VIEW A, WLI_QS_REPORT_ATTRIBUTE B, WLI_QS_REPORT_DATA C
where A.MSG_GUID = B.MSG_GUID and C.MSG_GUID = B.MSG_GUID  and ( v_now - B.DB_TIMESTAMP) * 24 * 3600 > v_delay_in_seconds;

WLI_REP_ARCHIVE_LOG_INS('1:INSERT', To_char( SQL%ROWCOUNT ) || ' records inserted into WLI_REPORTING_ARCHIVE older than ' || v_delay_in_seconds || ' seconds');

delete from WLI_QS_REPORT_ATTRIBUTE B where ( v_now - B.DB_TIMESTAMP) * 24 * 3600 > v_delay_in_seconds ;


WLI_REP_ARCHIVE_LOG_INS('2:DELETE', To_char( SQL%ROWCOUNT ) || ' records deleted from WLI_QS_REPORT_ATTRIBUTE older than ' || v_delay_in_seconds || ' seconds');

commit;
end loop;

end;
/





rebuilding indexes to speed up the OSB reporting

Aparently there is a heated debate on whether rebuilding indexes is actually helpful. To me, it worked like a charm.
Before, a simple "select count(*) from WLI_QS_REPORT_ATTRIBUTE;" would take 15 seconds, even if my table was almost empty.
After the rebuild, it was taking milliseconds.



ALTER INDEX IX_WLI_QS_REPORT_ATTRIBUTE_DM REBUILD;
ALTER INDEX IX_WLI_QS_REPORT_ATTRIBUTE_IED REBUILD;


This wiki contrains a lot of valuable advice on how to monitor index usage: http://www.orafaq.com/wiki/Oracle_database_Performance_Tuning_FAQ

Friday, November 23, 2012

Oracle DB: deleting a HUGE table a chunk at a time in a loop

This is just an example, of course TRUNC will be much faster... but if you need to select specific records, you have no choice.....

DECLARE
  nCount  NUMBER; 
  sql1 VARCHAR2(2000);
BEGIN
  
  nCount := 0;
  sql1 := 'delete from WLI_QS_REPORT_DATA where rownum < 10000';
  LOOP
    
    EXECUTE IMMEDIATE sql1;
    nCount := sql%rowcount;
    DBMS_OUTPUT.PUT_LINE('deleted records: ' || to_char(ncount) );
    commit;    

    EXIT WHEN nCount = 0;

  END LOOP;
end;
/




Oracle DB: count rows in a table

select COUNT(*) from WLI_REPORTING_ARCHIVE;
1513854

TECHNICALMESSAGEID can be null, and there is an INDEX on it:
select COUNT(TECHNICALMESSAGEID ) from WLI_REPORTING_ARCHIVE;
1513824
The difference is 30
select COUNT(*) from WLI_REPORTING_ARCHIVE where TECHNICALMESSAGEID is NULL;
30

of course
select COUNT(TECHNICALMESSAGEID) from WLI_REPORTING_ARCHIVE where TECHNICALMESSAGEID is null;
will immediately return 0
(it's very fast because probably the index keeps track of NULL entries)

This is not very accurate

SELECT NUM_ROWS FROM USER_TABLES WHERE TABLE_NAME = 'WLI_REPORTING_ARCHIVE';

unless the table has just been analyzed

This is VERY inaccurate
SELECT NUM_ROWS FROM USER_TABLES WHERE TABLE_NAME = 'WLI_REPORTING_ARCHIVE';

This is very accurate and fast
SELECT COUNT(*) * 100 FROM WLI_REPORTING_ARCHIVE SAMPLE (1);

explain plan for select COUNT(*) from WLI_REPORTING_ARCHIVE;

select * from table(dbms_xplan.display);

-----------------------------------------------------------------------------------------------
| Id  | Operation             | Name                          | Rows  | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |                               |     1 |  2921   (1)| 00:00:36 |
|   1 |  SORT AGGREGATE       |                               |     1 |            |          |
|   2 |   INDEX FAST FULL SCAN| WLI_REP_ARCHIVE_INDEX1 |  1499K|  2921   (1)| 00:00:36 |
-----------------------------------------------------------------------------------------------





see http://stackoverflow.com/questions/1840538/faster-alternative-in-oracle-to-select-count-from-sometable

WebLogic unlock account with WLST

/opt/oracle/fmw11_1_1_5/osb/common/bin/wlst.sh

connect('myuser', 'weblogic1', 't3://hqchnesoa104.acme.com:7001')

serverRuntime()

cd('ServerSecurityRuntime/osbts1as/DefaultRealmRuntime/myrealm/UserLockoutManagerRuntime/UserLockoutManager')

cmo.clearLockout('weblogic')

ls()

-r--   InvalidLoginAttemptsTotalCount               21171
-r--   InvalidLoginUsersHighCount                   2
-r--   LockedUsersCurrentCount                      1
-r--   LoginAttemptsWhileLockedTotalCount           20909
-r--   Name                                         UserLockoutManager
-r--   Type                                         UserLockoutManagerRuntime
-r--   UnlockedUsersTotalCount                      50
-r--   UserLockoutTotalCount                        51

-r-x   clearLockout                                 Void : String(userName)
-r-x   getLastLoginFailure                          Long : String(userName)
-r-x   getLoginFailureCount                         Long : String(userName)
-r-x   isLockedOut                                  Boolean : String(userName)
-r-x   preDeregister                                Void :



see also for Java code:
http://weblogic-wonders.com/weblogic/2010/11/12/userlockout-feature-of-weblogic-server/