Saturday, April 30, 2016

SSH

See here first if network has issues http://gvace.blogspot.com/2016/04/linux-network-configs.html

Without password

  1. Client save its public key to remote ssh server.
  2. When ssh login, remote ssh server send client a random string.
  3. Client use its private key to encrypt this random string.
  4. Client send ssh server the encrypted string.
  5. SSH server use saved public key to decrypt.
  6. If decrypt succeed, ssh server allow client to login, without password.



ssh client

Generate key
ssh-keygen -t rsa
generated public and private key will be in ~/.ssh
private key file: id_rsa
public key file: id_rsa.pub


copy the public key to target ssh-server
ssh-copy-id user1@192.168.3.4
this command will copy the public key from client to ssh server, saved in ~/.ssh/authorized_keys

keep public key and private key in ssh-client side

ssh server

Check if SSH is running
sudo netstat -anp | grep sshd
If nothing on port 22, means ssh-server is not running, install ssh-server or start it.

check firewall(iptables which is ufw), make sure ssh can go through



















Linux Network configs

Check port 61616
netstat -an|grep "61616"


Which program is using port 61616
netstat -nlap|grep 61616




check all networks
ifconfig -a

Config IP address dhcp netmask gateway etc..

/etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto em1
iface em1 inet dhcp
# This is an autoconfigured IPv6 interface
iface em1 inet6 auto
#another
auto enp0s3
iface enp0s3 inet static
address 192.168.56.95
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255



Change hostname
/etc/hostname

Assign ip to hostname
/etc/hosts



iptables

ubuntu
https://help.ubuntu.com/community/IptablesHowTo
sudo iptables -L

centOS
service iptables status


See what port is opened
netstat -tnlp








Friday, April 29, 2016

REST

REST Representational State Transfer


Representational
In any form: XML, JSON, HTML

State
More concerned with the state of a resource than with the actions we can take against resources.

Transfer
Trensfering data

Transfering the state of resources- in whatever form is most appropriate--from a server to a client(or client to server)





Wednesday, April 27, 2016

Spring Transaction Isolation Level

Spring Transaction Isolation Level

The standard levels are 2,3,4,5, the higher level, the poorer concurrency/effi
  1. ISOLATION_DEFAULT (Spring)
    This is a PlatformTransactionManager Default isolation level, using Default Database transaction level. The other 4 are correspond to JDBC isolation level
  2. ISOLATION_READ_UNCOMMITTED
    Lowest isolation level. Allow other transaction to see the data from this transaction. This level can cause dirty read, non-repeatable read, and illusion read
  3. ISOLATION_READ_COMMITTED (normally used)
    Promise other transaction can read data until this transaction committed.
  4. ISOLATION_REPEATABLE_READ
    Prevent dirty read, non-repeatable read. But can illusion read.
  5. ISOLATION_SERIALIZABLE
    This is most expensive level, but most reliable. It promise Sequence. Prevent dirty read, non-repeatable read, and illusion read

Transaction Definition

Transaction Definition

  1. PROPAGATION_REQUIRED (normally used)
    If transaction existed, use it, otherwise open a new transaction
  2. PROPAGATION_SUPPORTS
    If transaction existed, use it, otherwise run as non-transaction
  3. PROPAGATION_MANDATORY
    If transaction existed, use it, otherwise throw Exception
  4. PROPAGATION_REQUIRES_NEW
    Always open a new transaction, if transaction existed, hang up the existed transaction
  5. PROPAGATION_NOT_SUPPORTED
    Always run without transaction, if transaction existed, hang up the existed transaction
  6. PROPAGATION_NEVER
    Always run without transaction, if transaction existed, throw Exception
  7. PROPAGATION_NESTED (in Spring)
    If transaction existed, run nested transaction inside the existed transaction.
    If no transaction existed, run as PROPAGATION_REQUIRED

PropagationT1 NoneT1 Existed
REQUIREDT2=>newT1
SUPPORTST2 NoneT1
MANDATORYT2 ExceptionT1
REQUIRES_NEWT2=>newT2=>new
NOT_SUPPORTEDNoneHang up T1
NEVERNoneT2 Exception
NESTEDAs REQUIREDNested

Log


Three main types of log

  • Operation Log
  • Safety Log
  • Event Log

Dynamic Proxy: JDK VS CGLIB

If target object implements interface, by default, spring will use Dynamic Proxy from JDK for AOP.
If target object implements interface, we can force to use CGLIB to make Dynamic Proxy for AOP.
If target object does not implements interface, we MUST use CGLIB to make Dynamic Proxy for AOP.

In conclusion:
JDK can only apply to class which implements interface
CGLIB can apply to class with/without implementing interface

Spring will dynamically choose to use JDK or CGLIB for each target object.


JDK proxy example:
userManager $Proxy2  (id=42)
h JdkDynamicAopProxy  (id=54)

CGLIB example:
UserManagerImpl$$EnhancerBySpringCGLIB$$7f895f28  (id=46)

You can see CGLIB extends the target class to generate proxy, JDK did not
Because CGLIB do extends, our target class should NOT be final

to Enable CGLIB:

dependency:
<dependency>
 <groupId>cglib</groupId>
 <artifactId>cglib</artifactId>
 <version>3.2.2</version>
</dependency>

applicationContext.xml config

<!-- proxy-target-class="true" means force to use CGLIB -->
<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>

But if we want spring to choose for us, we don't have to force to do the config, just add dependency.