Monday, November 26, 2012

Run remote commands by powershell


--ref: http://searchsystemschannel.techtarget.com/feature/PowerShell-remoting-in-Windows-Server-2008-R2

--1. enable remote on server e.g. xxx

PS C:\Users\oraexec> Enable-PSRemoting

WinRM Quick Configuration
Running command "Set-WSManQuickConfig" to enable this machine for remote management through WinRM service.
 This includes:
    1. Starting or restarting (if already started) the WinRM service
    2. Setting the WinRM service type to auto start
    3. Creating a listener to accept requests on any IP address
    4. Enabling firewall exception for WS-Management traffic (for http only).

Do you want to continue?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
WinRM already is set up to receive requests on this machine.
WinRM has been updated for remote management.
Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.
WinRM firewall exception enabled.


Confirm
Are you sure you want to perform this action?
Performing operation "Registering session configuration" on Target "Session configuration "Microsoft.PowerShell32" is
not found. Running command "Register-PSSessionConfiguration Microsoft.PowerShell32 -processorarchitecture x86 -force"
to create "Microsoft.PowerShell32" session configuration. This will restart WinRM service.".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
PS C:\Users\oraexec>

--2. add to trust on client
If you are managing a remote computer from a computer that is running Windows 7, start the Windows Remote Management (WinRM) service to allow for the addition of trusted hosts. Open a Command Prompt session with elevated user rights by clicking Start, clicking All Programs, clicking Accessories, right-clicking Command Prompt, and then clicking Run as administrator. Type the following, and then press Enter: net start winrm
For remote connections in a Workgroup to Workgroup/Domain scenario, the remote computer must be added to the trusted hosts list on the source computer. To do this, run the following command on the source computer in a Command Prompt window that is opened with elevated user rights.
winrm set winrm/config/client @{TrustedHosts="RemoteComputerName"}
For remote connections in a Workgroup to Workgroup/Domain scenario, if a user is not logged on by using the source computer’s built-in administrator account, the following WinRM registry key must be configured to allow remote access from the source computer. This change is required because of a User Account Control (UAC) limitation on non-administrator accounts that are members of the Administrators group. To change this registry key, run the following command on the source computer at a command prompt that is opened with elevated user rights.
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
By default, WinRM allows for a maximum of five connections to a remote computer to be active per user. To increase the limit, run the following command on the source computer, in which X represents the number of connections that you want to allow, at a command prompt that is opened with elevated user rights.
winrm s winrm/config/winrs @{MaxShellsPerUser="X"}


winrm set winrm/config/client @{TrustedHosts="xxxxx"}

--3. run powershell on client
 $host.version

--4. test connection with remote
PS H:\> Test-WSMan xxxxx


wsmid           : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor   : Microsoft Corporation
ProductVersion  : OS: 0.0.0 SP: 0.0 Stack: 2.0

--remote commands
Invoke-Command -ComputerName Monolith -ScriptBlock { Get-ChildItem C:\ } -credential chris
Invoke-Command [-FilePath] [[-ComputerName] ]

Invoke-Command -ScriptBlock {E:\scripts\test.cmd} -ComputerName cepaoas91 -credential cepaoas91\oraremote

--5. enter remote session
Enter-PSSession -ComputerName server1 -Credential domain\user

Enter-PSSession -ComputerName server1 -Credential domain\user



Tuesday, June 5, 2012

Setup Android SDK in Titanium studio

1. follow instructions to download and install https://wiki.appcelerator.org/display/guides/Installing+and+Updating+Android+SDK

2 Install google NDK

3. configure SDK in titanium preference


Monday, May 28, 2012

How to display all markers in KML on google map.

1. create your map on google.
2. upload kml
3. right click link of kml shows on google map and copy link address
4. put link address in search box on google map. Now it shows all markers
5. copy the link in address box, and put it in your applicaiton or plug-in s.

e.g.https://maps.google.com/maps?q=http://maps.google.com/maps/ms%3Fauthuser%3D0%26vps%3D7%26hl%3Den%26ie%3DUTF8%26oe%3DUTF8%26msa%3D0%26output%3Dkml%26msid%3D206738220065198958312.0004b30f84e45cd59ff3a&hl=en&sll=37.0625,-95.677068&sspn=56.987104,114.785156&vpsrc=0&t=h&z=11

Friday, February 3, 2012

test Oracle webservice by PL/SQL

--load java for webservice
--ref: DBWS Callout Utilities User's Guide for RDBMS 10.1 or 10.2 [ID 428775.1]
--http://docs.oracle.com/cd/B19306_01/java.102/b14188/intro.htm#BHCIBFGJ
--download:http://download.oracle.com/technology/sample_code/tech/java/jsp/dbws-callout-utility-10131.zip

--to load java make sure using right java version

export PATH=$ORACLE_HOME/jdk/bin:$PATH

loadjava -u rsong/slb -r -v -f -genmissing dbwsclientws.jar dbwsclientdb11.jar

--test ref: http://www.oracle-base.com/articles/10g/utl_dbws10g.php

CREATE OR REPLACE FUNCTION add_numbers (p_int_1 IN NUMBER,
p_int_2 IN NUMBER)
RETURN NUMBER
AS
l_service RSONG.UTL_DBWS.service;
l_call RSONG.UTL_DBWS.call;
l_wsdl_url VARCHAR2(32767);
l_namespace VARCHAR2(32767);
l_service_qname RSONG.UTL_DBWS.qname;
l_port_qname RSONG.UTL_DBWS.qname;
l_operation_qname RSONG.UTL_DBWS.qname;

l_xmltype_in SYS.XMLTYPE;
l_xmltype_out SYS.XMLTYPE;
l_return NUMBER;
BEGIN
l_wsdl_url := 'http://www.oracle-base.com/webservices/server.php?wsdl';
l_namespace := 'http://www.oracle-base.com/webservices/';

l_service_qname := RSONG.UTL_DBWS.to_qname(l_namespace, 'Calculator');
l_port_qname := RSONG.UTL_DBWS.to_qname(l_namespace, 'CalculatorPort');
l_operation_qname := RSONG.UTL_DBWS.to_qname(l_namespace, 'ws_add');

l_service := RSONG.UTL_DBWS.create_service (
wsdl_document_location => URIFACTORY.getURI(l_wsdl_url),
service_name => l_service_qname);

l_call := RSONG.UTL_DBWS.create_call (
service_handle => l_service,
port_name => l_port_qname,
operation_name => l_operation_qname);

l_xmltype_in := SYS.XMLTYPE('
' || p_int_1 || '
' || p_int_2 || '
');
l_xmltype_out := RSONG.UTL_DBWS.invoke(call_Handle => l_call,
request => l_xmltype_in);
RSONG.UTL_DBWS.release_call (call_handle => l_call);
RSONG.UTL_DBWS.release_service (service_handle => l_service);

l_return := l_xmltype_out.extract('//return/text()').getNumberVal();
RETURN l_return;
END;
/

exec dbms_java.grant_permission( 'RSONG', 'SYS:java.lang.RuntimePermission', 'getClassLoader', '' );
select add_numbers(1,2) from dual;

DBAREPO1 SQL> /
select add_numbers(1,2) from dual
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.IllegalAccessException: java.lang.NoClassDefFoundError
ORA-06512: at "RSONG.UTL_DBWS", line 193
ORA-06512: at "RSONG.UTL_DBWS", line 190
ORA-06512: at "RSONG.ADD_NUMBERS", line 25


--debug
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','shutdownHooks','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','setFactory','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','accessClassInPackage.sun.util.calendar','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','getClassLoader','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','createClassLoader','');
exec dbms_java.grant_permission('RSONG','SYS:java.util.logging.LoggingPermission','control','');
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxySet','write' );
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxyHost','write');
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxyPort','write');

exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','*','read,write,resolve,connect');

-- shows true error
DBAREPO1 SQL> select add_numbers(1,2) from dual;
select add_numbers(1,2) from dual
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.IllegalAccessException: error.build.wsdl.model:
oracle.j2ee.ws.common.tools.api.WsdlValidationException: Failed to setup HTTP
Connection to URL: "http://www.oracle-base.com/webservices/server.php?wsdl",
caused by: java.security.AccessControlException. : the Permission
(java.net.SocketPermission www.oracle-base.com resolve) has not been granted to
RSONG. The PL/SQL to grant this is dbms_java.grant_permission( 'RSONG','SYS:java.net.SocketPermission', 'www.oracle-base.com', 'resolve' )
ORA-06512: at "RSONG.UTL_DBWS", line 193
ORA-06512: at "RSONG.UTL_DBWS", line 190
ORA-06512: at "RSONG.ADD_NUMBERS", line 25



exec dbms_java.grant_permission('RSONG', 'SYS:java.net.SocketPermission', '88.208.252.198:80','connect,resolve' );

DBAREPO1 SQL> select add_numbers(1,2) from dual;
select add_numbers(1,2) from dual
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.ExceptionInInitializerError
ORA-06512: at "RSONG.UTL_DBWS", line 404
ORA-06512: at "RSONG.UTL_DBWS", line 401
ORA-06512: at "RSONG.ADD_NUMBERS", line 39

--finally
exec dbms_java.grant_permission( 'RSONG', 'SYS:java.util.PropertyPermission', 'HTTPClient.socket.idleTimeout', 'write' );

DBAREPO2 SQL> select add_numbers(1,2) from dual;

ADD_NUMBERS(1,2)
----------------
3
--overall permissions
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','shutdownHooks','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','setFactory','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','accessClassInPackage.sun.util.calendar','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','getClassLoader','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','createClassLoader','');
exec dbms_java.grant_permission('RSONG','SYS:java.util.logging.LoggingPermission','control','');
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxySet','write' );
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxyHost','write');
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxyPort','write');

exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','*','read,write,resolve,connect');

exec dbms_java.grant_permission('RSONG', 'SYS:java.net.SocketPermission', '88.208.252.198:80','connect,resolve' );

exec dbms_java.grant_permission( 'RSONG', 'SYS:java.util.PropertyPermission', 'HTTPClient.socket.idleTimeout', 'write' );

Wednesday, January 11, 2012

11R2 RAC listener and service name clarify

1. Service name
In Oracle RAC you should not change service_names in initxxx.ora parameter file. You need use servctl utility to add,remove a service name and the utility will update parameter file.http://docs.oracle.com/cd/E11882_01/rac.112/e17264/configwlm.htm#CHDJIAJH

2. Listener
From 11R2 start using SCAN listener. there is one bug that DBCA does not recognize parameter format like orarac1-scan:1521.
The workaround will be
a) set remote_listener to '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=162.106.114.130)(PORT=1521)))(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=162.106.114.131)(PORT=1521))))' which applied to database running under version 11R1 or before
b) set remote_listener to 'orarac1-scan:1521' in sqlplus after database is created.

3. client connection process
a) a client contact listener listed in tnsnames.ora. 11R2 client can handle multiple address with a name but the version before does not.
b)make hand shake with the listener(scan listener), if it fails client 11R1 or before will fail. 11r2 client will try next ip returned by scan name and so on.
c) if client success make hand shake with scan listener then scan listener will find service registered in RAC and try find a instance which has less workload.
If there is no service registered, it will use information registered in listener which has instance lists.
d) pass connect to that instance(load balancing) or random instance if there is no workload information found in previous step.
e) connection made.

Tuesday, January 3, 2012

Oracle RAC patch 11.2.0.3 quit due to fatal error Unable to obtain network interface list from Oracle ClusterwarePRCT-1302 : The "with" has an invalid

##bug OIFCFG Reports PRIF-30 after Successful Upgrade to 11gR2 Grid Infrastructure [ID 983718.1] ##
## bug 8632280 ###
olive /dbaadm/bu/bin/patch/patchset11203/GI/grid$ oifcfg getif
nxge1 162.106.225.0 global cluster_interconnect
Only in OCR: nxge0 162.106.114.0 global public
PRIF-30: Network information in OCR profile needs to be synced with GPnP profile
olive /dbaadm/bu/bin/patch/patchset11203/GI/grid$ oifcfg delif -global nxge1
olive /dbaadm/bu/bin/patch/patchset11203/GI/grid$ oifcfg setif -global nxge0/162.106.114.0:public
olive /dbaadm/bu/bin/patch/patchset11203/GI/grid$ oifcfg getif
nxge0 162.106.114.0 global public

RAC commands crsctl and srvctl

#commands used often
#/u01/app/11.2.0/grid/bin/srvctl add scan_listener
#/u01/app/11.2.0/grid/bin/srvctl start scan_listener
#/u01/app/11.2.0/grid/bin/ocrconfig -export /home/oragrid/install/ocrconfig.dump
#/u01/app/11.2.0/grid/bin/srvctl remove nodeapps
#/u01/app/11.2.0/grid/bin/srvctl add nodeapps -n oak -A oak-vip/255.255.255.0
#/u01/app/11.2.0/grid/bin/srvctl add nodeapps -n olive -A olive-vip/255.255.255.0
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.LISTENER_SCAN1.lsnr -o oragrid
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.LISTENER_SCAN2.lsnr -o oragrid
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.eons -o oragrid
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.gsd -o oragrid
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.ons -o oragrid
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.net1.network -u 'user:oragrid:r-x'
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.net1.network -x 'user:oracrs:r-x'
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.oak.vip -x 'user:oracrs:r-x'
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.oak.vip -u 'user:oragrid:r-x'
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.olive.vip -x 'user:oracrs:r-x'
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.olive.vip -u 'user:oragrid:r-x'
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.scan1.vip -x 'user:oracrs:r-x'
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.scan1.vip -u 'user:oragrid:r-x'
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.scan2.vip -x 'user:oracrs:r-x'
#/u01/app/11.2.0/grid/bin/crsctl setperm resource ora.scan2.vip -u 'user:oragrid:r-x'