Thursday, February 22, 2018

Apache!

Docs http://httpd.apache.org/docs/2.4/

Docker image https://hub.docker.com/_/httpd/

mkdir myapp
cd myapp
docker run -dit --name my-apache-app -p 8080:80 httpd:2.4

http://localhost:8080/index.html should display "it works"


To install on Centos7:
sudo yum update
sudo yum install httpd
sudo systemctl start httpd.service
sudo systemctl enable httpd.service

and configuration file is /etc/httpd/conf/httpd.conf, files in /var/www/html/
sudo chmod 777 /var/www/html/
vi /var/www/html/index.html
http://localhost:80

Directives docs http://httpd.apache.org/docs/2.4/mod/directives.html

Virtualhost directive http://httpd.apache.org/docs/2.4/mod/core.html#virtualhost



Interesting article on Nginx vs Apache https://poweruphosting.com/blog/apache-vs-nginx/


To debug:
/usr/sbin/httpd -t
/usr/sbin/httpd -t -f /u01/app/mware/httpd/conf/jboss.conf
/usr/sbin/httpd -e debug
/usr/sbin/httpd -M
/usr/sbin/httpd -S (Priceless! to dump current configuration)






JBoss modules

https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/6.1/html/development_guide/chap-class_loading_and_modules



https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7





Tuesday, February 20, 2018

groovysh and X11

Running groovysh I get this error:


java.awt.AWTError: Can't connect to X11 window server using 'myserver:0.0' as the value of the DISPLAY variable

Really weird.... I could fix it only by "unset DISPLAY".

Complete stacktrace is:


java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:126)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.awt.Toolkit$2.run(Toolkit.java:860)
at java.awt.Toolkit$2.run(Toolkit.java:855)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
at java.awt.Desktop.isDesktopSupported(Desktop.java:169)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1850)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3758)
at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.getProperty(ClassMetaClassGetPropertySite.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)
at org.codehaus.groovy.tools.shell.commands.DocCommand.<clinit>(DocCommand.groovy:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
at org.codehaus.groovy.tools.shell.util.DefaultCommandsRegistrar.register(DefaultCommandsRegistrar.groovy:82)
at org.codehaus.groovy.tools.shell.util.DefaultCommandsRegistrar$register.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at org.codehaus.groovy.tools.shell.Groovysh$_createDefaultRegistrar_closure3.doCall(Groovysh.groovy:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at org.codehaus.groovy.tools.shell.Groovysh.<init>(Groovysh.groovy:103)
at org.codehaus.groovy.tools.shell.Groovysh.<init>(Groovysh.groovy:122)
at org.codehaus.groovy.tools.shell.Groovysh.<init>(Groovysh.groovy:126)
at org.codehaus.groovy.tools.shell.Groovysh.<init>(Groovysh.groovy:130)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
at org.codehaus.groovy.tools.shell.Main.<init>(Main.groovy:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
at org.codehaus.groovy.tools.shell.Main.main(Main.groovy:151)





Thursday, February 15, 2018

VMWare, vRealize and Docker

here some statements about vRealize Automation (VRA) https://blogs.vmware.com/management/2017/07/container-management-vrealize-automation.html

This is the homepage:
https://www.vmware.com/products/vrealize-automation.html

You can quickly open a free account and start an online lab (again, FREE) of vRealize Automation

Hands-on Lab manual is available here http://docs.hol.vmware.com/

I have done the "HOL-1821-01-CMP vRealize Automation 7 - Getting Started"

There is even a course "HOL-1830-02-CNA vSphere Integrated Containers - Getting Started" available at https://www.vmware.com/go/try-vic-hol


This PDF is about VIC containers https://www.vmware.com/content/dam/digitalmarketing/vmware/en/pdf/solutionbrief/vmware-vic-developer-sandbox-use-case.pdf

Monday, February 12, 2018

Oracle XE DB running as Docker Container, and a freaky Docker error

https://hub.docker.com/r/sath89/oracle-xe-11g/

docker run -d -p 8080:8080 -p 1521:1521 sath89/oracle-xe-11g


Error response from daemon: updating the store state of sandbox failed: failed to update store for object type *libnetwork.sbState: json: cannot unmarshal string into Go struct field sbState.ExtDNS of type libnetwork.extDNSEntry.

it seems that the only way to solve it is:

sudo rm -rf /var/lib/docker

then reboot

I did so and it worked (but of course I have lost all my images and containers).

Scary.

Friday, February 9, 2018

screen : how to run long running linux commands who survive also a VDI crash

https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/

example:

screen
CTRL-A c (create new window)
top
CTRL-A c (create new window)
ls
CTRL-A n (next window)
You are now back in “top”


Restart VDI

Login again

screen –r (reattach)



With screen you can also open several terminal sessions from the same login, and tab through them with CTRL-A n


Monday, February 5, 2018

Maven version sorting with Java 8

You can easily sort versions in Maven using org.apache.maven.artifact.versioning.ComparableVersion :

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.pierre</groupId>
  <artifactId>mavensort</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
   <dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-artifact</artifactId>
    <version>3.5.2</version>
   </dependency>
  </dependencies>
</project>

package mavensort;

import org.apache.maven.artifact.versioning.ComparableVersion;

public class Artifact implements Comparable<Artifact> {
 int id;
 String version;
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getVersion() {
  return version;
 }
 public void setVersion(String version) {
  this.version = version;
 }
 public Artifact(int id, String version) {
  super();
  this.id = id;
  this.version = version;
 }

 public int compareTo(Artifact o) {
  
  ComparableVersion cv1 = new ComparableVersion(version);
  ComparableVersion cv2 = new ComparableVersion(o.getVersion());
  int compareTo = cv1.compareTo(cv2);
  System.out.println("compareTo " + version + " " + o.getVersion() + " " + compareTo);
  return compareTo;
 }
 

}


package mavensort;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.apache.maven.artifact.versioning.ComparableVersion;
import org.junit.Test;

public class ArtifactTest {

 @Test
 public void testSort() {
  String version1 = "1.2";
  ComparableVersion cv1 = new ComparableVersion(version1);
  String version2 = "1.12";
  ComparableVersion cv2 = new ComparableVersion(version2);
  assert(cv1.compareTo(cv2) < 0);

 }
 
 @Test
 public void testSortCollection() {
  Artifact a1 = new Artifact(1, "1.2");
  Artifact a2 = new Artifact(2, "1.12");
  Artifact a3 = new Artifact(3, "0.12");
  List<Artifact> list = Arrays.asList(a1, a2, a3);
  Supplier<List<Artifact>> supplier = () -> new ArrayList<Artifact>();
  List<Artifact> sortedList = list.stream().sorted().collect(Collectors.toCollection(supplier));
  sortedList.forEach(item -> System.out.println(item.version));
  
 }

}


The use of streams and Supplier just to sort a collection is voodoistic. One can simply code this:

Collections.sort(list);
list.forEach(item -> System.out.println(item.version));


You can use also an external comparator:

@Test
 public void testSortCollectionExternalComparator() {
  Artifact a1 = new Artifact(1, "1.2");
  Artifact a2 = new Artifact(2, "1.12");
  Artifact a3 = new Artifact(3, "0.12");
  List<Artifact> list = Arrays.asList(a1, a2, a3);
  list.sort(new ArtifactComparator());
  list.forEach(item -> System.out.println(item.version));
  
 }


public class ArtifactComparator implements Comparator<Artifact> {

 @Override
 public int compare(Artifact o1, Artifact o2) {
  ComparableVersion cv1 = new ComparableVersion(o1.getVersion());
  ComparableVersion cv2 = new ComparableVersion(o2.getVersion());
  int compareTo = cv1.compareTo(cv2);
  System.out.println("C2 compareTo " + o1.getVersion() + " " + o2.getVersion() + " " + compareTo);
  return compareTo;
 }

}



Maven dependency is

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.6.0</version>
</dependency>





The external dependency is not necessary, you can simply copy the class https://raw.githubusercontent.com/apache/maven/master/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java into your project, luckily it has no other dependencies to other classes in the same package

Ref: https://www.geeksforgeeks.org/collections-sort-java-examples/ for comparators



Friday, February 2, 2018

Kerberos

https://en.wikipedia.org/wiki/Kerberos_(protocol)

symmetric key cryptography + trusted 3rd party
UDP port 88



https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html/how_to_set_up_sso_with_kerberos/sso_with_kerberos_deeper_dive




https://en.wikipedia.org/wiki/Generic_Security_Services_Application_Program_Interface



KDC = Key Distribution Center

TGT = Ticket-Getting Ticket

AS = Authorization Server

ST = Service Ticket

TGS = Ticket Granting Service

SPN = Service Principal Name

1) AS-REQ / AS-REP : user logs in, using key in keytab file he authenticates in AS/KDC. AS/KDC checks if user exists in its DB. User gets a TGT (time limited)
2) user


Kerberos uses a keytab file https://kb.iu.edu/d/aumh

Microsoft articles:

https://technet.microsoft.com/en-us/library/cc772815(v=ws.10).aspx

https://msdn.microsoft.com/en-us/library/cc246080.aspx

Microsoft Kerberos training videos (4):

https://www.youtube.com/playlist?list=PL97898A4367BC1A7B

Kerberos Constrained Delegation https://docs.microsoft.com/en-us/windows-server/security/kerberos/kerberos-constrained-delegation-overview