b439b38ed24e473a8c7a45bf48154a1c39914a01
[armband.git] / patches / fuel-plugin-opendaylight / 0001-arm64-support-for-OpenDaylight-Fuel-Plugin.patch
1 From: Florin Dumitrascu <florin.dumitrascu@enea.com>
2 Date: Thu, 17 Mar 2016 18:15:42 +0100
3 Subject: [PATCH] arm64 support for OpenDaylight Fuel Plugin
4
5 ODL depends on a native library (leveldb).
6 ODL Beryllium version is still using a native x86 version of
7 this library (wrapped in leveldbjni). There is no upstream version
8 of leveldbjni supporting arm64 leveldb, so we need to compile it
9 when deploying ODL. This is done when running odl-install puppet manifest.
10 For more info about this ODL limitation, read here:
11 https://bugs.opendaylight.org/show_bug.cgi?id=3973
12
13 Signed-off-by: Florin Dumitrascu <florin.dumitrascu@enea.com>
14 ---
15  .../modules/opendaylight/files/leveldb-arm64.patch |  36 +++++
16  .../opendaylight/files/leveldbjni-native.patch     |  23 ++++
17  .../puppet/modules/opendaylight/manifests/init.pp  |   8 ++
18  .../modules/opendaylight/manifests/install.pp      |  12 +-
19  .../modules/opendaylight/manifests/leveldbjni.pp   | 150 +++++++++++++++++++++
20  deployment_tasks.yaml                              |   2 +-
21  odl_package/ubuntu/opendaylight                    |   4 +-
22  pre_build_hook                                     |   9 +-
23  8 files changed, 235 insertions(+), 9 deletions(-)
24  create mode 100644 deployment_scripts/puppet/modules/opendaylight/files/leveldb-arm64.patch
25  create mode 100644 deployment_scripts/puppet/modules/opendaylight/files/leveldbjni-native.patch
26  create mode 100644 deployment_scripts/puppet/modules/opendaylight/manifests/leveldbjni.pp
27
28 diff --git a/deployment_scripts/puppet/modules/opendaylight/files/leveldb-arm64.patch b/deployment_scripts/puppet/modules/opendaylight/files/leveldb-arm64.patch
29 new file mode 100644
30 index 0000000..c72efeb
31 --- /dev/null
32 +++ b/deployment_scripts/puppet/modules/opendaylight/files/leveldb-arm64.patch
33 @@ -0,0 +1,36 @@
34 +diff --git a/port/atomic_pointer.h b/port/atomic_pointer.h
35 +index e17bf43..78cb6b3 100644
36 +--- a/port/atomic_pointer.h
37 ++++ b/port/atomic_pointer.h
38 +@@ -36,6 +36,8 @@
39 + #define ARCH_CPU_X86_FAMILY 1
40 + #elif defined(__ARMEL__)
41 + #define ARCH_CPU_ARM_FAMILY 1
42 ++#elif defined(__aarch64__)
43 ++#define ARCH_CPU_ARM64_FAMILY 1
44 + #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
45 + #define ARCH_CPU_PPC_FAMILY 1
46 + #endif
47 +@@ -93,6 +95,13 @@ inline void MemoryBarrier() {
48 + }
49 + #define LEVELDB_HAVE_MEMORY_BARRIER
50 +
51 ++// ARM64
52 ++#elif defined(ARCH_CPU_ARM64_FAMILY)
53 ++inline void MemoryBarrier() {
54 ++ asm volatile("dmb sy" : : : "memory");
55 ++}
56 ++#define LEVELDB_HAVE_MEMORY_BARRIER
57 ++
58 + // PPC
59 + #elif defined(ARCH_CPU_PPC_FAMILY) && defined(__GNUC__)
60 + inline void MemoryBarrier() {
61 +@@ -216,6 +225,7 @@ class AtomicPointer {
62 + #undef LEVELDB_HAVE_MEMORY_BARRIER
63 + #undef ARCH_CPU_X86_FAMILY
64 + #undef ARCH_CPU_ARM_FAMILY
65 ++#undef ARCH_CPU_ARM64_FAMILY
66 + #undef ARCH_CPU_PPC_FAMILY
67 +
68 + }  // namespace port
69 +
70 diff --git a/deployment_scripts/puppet/modules/opendaylight/files/leveldbjni-native.patch b/deployment_scripts/puppet/modules/opendaylight/files/leveldbjni-native.patch
71 new file mode 100644
72 index 0000000..7520205
73 --- /dev/null
74 +++ b/deployment_scripts/puppet/modules/opendaylight/files/leveldbjni-native.patch
75 @@ -0,0 +1,23 @@
76 +diff --git a/leveldbjni-all/pom.xml b/leveldbjni-all/pom.xml
77 +index 426f2a6..c4a2a16 100755
78 +--- a/leveldbjni-all/pom.xml
79 ++++ b/leveldbjni-all/pom.xml
80 +@@ -41,7 +41,7 @@
81
82 +   <groupId>org.fusesource.leveldbjni</groupId>
83 +   <artifactId>leveldbjni-all</artifactId>
84 +-  <version>1.8</version>
85 ++  <version>1.8-odl</version>
86 +   <packaging>bundle</packaging>
87 +   
88 +   <name>${project.artifactId}</name>
89 +@@ -119,7 +119,8 @@
90 +               META-INF/native/osx/libleveldbjni.jnilib;osname=macosx;processor=x86,
91 +               META-INF/native/osx/libleveldbjni.jnilib;osname=macosx;processor=x86-64,
92 +               META-INF/native/linux32/libleveldbjni.so;osname=Linux;processor=x86,
93 +-              META-INF/native/linux64/libleveldbjni.so;osname=Linux;processor=x86-64
94 ++              META-INF/native/linux64/libleveldbjni.so;osname=Linux;processor=x86-64,
95 ++              META-INF/native/linux64/libleveldbjni.so;osname=Linux;processor=aarch64
96 +             </Bundle-NativeCode>
97 +          </instructions>
98 +         </configuration>
99 diff --git a/deployment_scripts/puppet/modules/opendaylight/manifests/init.pp b/deployment_scripts/puppet/modules/opendaylight/manifests/init.pp
100 index 8dfb213..95b3de7 100644
101 --- a/deployment_scripts/puppet/modules/opendaylight/manifests/init.pp
102 +++ b/deployment_scripts/puppet/modules/opendaylight/manifests/init.pp
103 @@ -8,4 +8,12 @@ class opendaylight {
104    $manager_ip_address = $odl_controller_hash[0]['internal_address']
105    $node_private_address = $node[0]['private_address']
106    $node_internal_address = $node[0]['internal_address']
107 +
108 +  $arch = $::architecture ? {
109 +    'aarch64' => $::osfamily ? {
110 +      'Debian' => 'arm64',
111 +      default  => 'aarch64',
112 +    },
113 +    default => $::architecture,
114 +  }
115  }
116 diff --git a/deployment_scripts/puppet/modules/opendaylight/manifests/install.pp b/deployment_scripts/puppet/modules/opendaylight/manifests/install.pp
117 index 7a3bf3f..f9bba56 100644
118 --- a/deployment_scripts/puppet/modules/opendaylight/manifests/install.pp
119 +++ b/deployment_scripts/puppet/modules/opendaylight/manifests/install.pp
120 @@ -19,6 +19,12 @@ class opendaylight::install (
121      ensure  => installed,
122    }
123  
124 +  if ($::osfamily == 'Debian' and $::opendaylight::arch == 'arm64') {
125 +    class { 'opendaylight::leveldbjni':
126 +      require => Package['opendaylight'],
127 +    }
128 +  }
129 +
130    package {'opnfv-quagga':
131      ensure => installed,
132    }
133 @@ -36,7 +42,8 @@ class opendaylight::install (
134  
135    debug("Set odl rest api port to ${rest_port}")
136  
137 -  file { "${conf_dir}/jetty.xml":
138 +  file { 'jetty.xml':
139 +    path    => "${conf_dir}/jetty.xml",
140      ensure  => file,
141      owner   => 'odl',
142      content => template('opendaylight/jetty.xml.erb')
143 @@ -72,6 +79,7 @@ class opendaylight::install (
144    Package['opendaylight'] ->
145    Ini_setting <||> ->
146    Firewall <||> ->
147 -  File <||> ->
148 +  File['jetty.xml'] ->
149 +  Class['opendaylight::leveldbjni'] ->
150    Service['opendaylight']
151  }
152 diff --git a/deployment_scripts/puppet/modules/opendaylight/manifests/leveldbjni.pp b/deployment_scripts/puppet/modules/opendaylight/manifests/leveldbjni.pp
153 new file mode 100644
154 index 0000000..c708611
155 --- /dev/null
156 +++ b/deployment_scripts/puppet/modules/opendaylight/manifests/leveldbjni.pp
157 @@ -0,0 +1,150 @@
158 +# == Class opendaylight::leveldbjni
159 +#
160 +# Manages compilation of JNI for leveldb.
161 +#
162 +# It compiles the leveldbjni from sources and patches it so that it's properly
163 +# detected by maven on arm64 system.
164 +#
165 +class opendaylight::leveldbjni(
166 +  $target = '/opt/opendaylight',
167 +  $user    = 'odl',
168 +  $branch  = 'leveldbjni-1.8',
169 +) {
170 +  case $::osfamily {
171 +    'Debian', 'Ubuntu': {}
172 +    default: {
173 +      fail('Not supported on OS other than Debian based.')
174 +    }
175 +  }
176 +
177 +  $libsnappy_dir = '/usr/lib'
178 +  $leveldb_dir = "${target}/leveldb"
179 +  $leveldbjni_dir = "${target}/leveldbjni"
180 +  $environment = ["SNAPPY_HOME=${libsnappy_dir}", "LEVELDB_HOME=${leveldb_dir}", "LEVELDBJNI_HOME=${leveldbjni_dir}", "LIBRARY_PATH=${libsnappy_dir}", "C_INCLUDE_PATH=${libsnappy_dir}", "CPLUS_INCLUDE_PATH=${libsnappy_dir}","JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-${::opendaylight::arch}"]
181 +  $parallel_jobs = ($processorcount + 1)/2
182 +
183 +  if ! defined(Package['git']) {
184 +    package { 'git':
185 +      ensure => 'present',
186 +    }
187 +  }
188 +  if ! defined(Package['build-essential']) {
189 +    package { 'build-essential':
190 +      ensure => 'present',
191 +    }
192 +  }
193 +  if ! defined(Package['automake']) {
194 +    package { 'automake':
195 +      ensure => 'present',
196 +    }
197 +  }
198 +  if ! defined(Package['make']) {
199 +    package { 'make':
200 +      ensure => 'present',
201 +    }
202 +  }
203 +  if ! defined(Package['libsnappy-dev']) {
204 +    package { 'libsnappy-dev':
205 +      ensure => 'present',
206 +    }
207 +  }
208 +  if ! defined(Package['patch']) {
209 +    package { 'patch':
210 +      ensure => 'present',
211 +    }
212 +  }
213 +  if ! defined(Package['maven']) {
214 +    package { 'maven':
215 +      ensure => 'present',
216 +    }
217 +  }
218 +  if ! defined(Package['openjdk-7-jdk']) { 
219 +    package { 'openjdk-7-jdk':
220 +      ensure => 'present',
221 +    }
222 +  }
223 +
224 +  exec { 'leveldb-fetch':
225 +    path    => ['/usr/bin'],
226 +    command => "git clone git://github.com/chirino/leveldb.git ${leveldb_dir}",
227 +    creates => "${leveldb_dir}/.git",
228 +    user    => $user,
229 +    require => [Package['git']],
230 +  } ->
231 +  exec { 'leveldbjni-fetch':
232 +    path    => ['/usr/bin'],
233 +    command => "git clone https://github.com/fusesource/leveldbjni.git -b ${branch} ${leveldbjni_dir}",
234 +    creates => "${leveldbjni_dir}/.git",
235 +    user    => $user,
236 +    require => [Package['git']],
237 +  } ->
238 +  exec { 'leveldb-merge-google':
239 +    path    => ['/usr/bin', '/bin'],
240 +    command => "git config user.name odl && git config user.email 'o@d.l' && git remote add google https://github.com/google/leveldb.git && git fetch google master && git fetch --tags google && git merge --no-edit v1.18",
241 +    unless  => "git remote | grep google",
242 +    cwd     => $leveldb_dir,
243 +    user    => $user,
244 +    require => [Package['git']],
245 +  } ->
246 +  exec { 'leveldb-patch':
247 +    path    => ['/usr/bin'],
248 +    command => "patch -p1 < ${leveldbjni_dir}/leveldb.patch",
249 +    unless  => "patch -p1 -R -N --dry-run < ${leveldbjni_dir}/leveldb.patch",
250 +    cwd     => $leveldb_dir,
251 +    user    => $user,
252 +    require => [Package['patch']],
253 +  } ->
254 +  file { "${leveldb_dir}/leveldb-arm64.patch":
255 +    ensure => "file",
256 +    source => "puppet:///modules/opendaylight/leveldb-arm64.patch",
257 +    owner  => $user,
258 +  } ->
259 +  exec { 'leveldb-patch-for-arm64':
260 +    path    => ['/usr/bin'],
261 +    command => "patch -p1 < ${leveldb_dir}/leveldb-arm64.patch",
262 +    unless  => "patch -p1 -R -N --dry-run < ${leveldb_dir}/leveldb-arm64.patch",
263 +    cwd     => $leveldb_dir,
264 +    user    => $user,
265 +    require => [Package['patch']],
266 +  } ->
267 +  exec { 'leveldb-build':
268 +    command => "/usr/bin/make libleveldb.a -j${parallel_jobs}",
269 +    creates => "${leveldb_dir}/libleveldb.a",
270 +    environment => $environment,
271 +    cwd     => $leveldb_dir,
272 +    user    => $user,
273 +    require => [Package['git'], Package['make'], Package['build-essential']],
274 +  } ->
275 +  file { "${leveldbjni_dir}/leveldbjni.patch":
276 +    ensure => "file",
277 +    source => "puppet:///modules/opendaylight/leveldbjni-native.patch",
278 +    owner  => $user,
279 +  } ->
280 +  exec { 'leveldbjni-patch':
281 +    path    => ['/usr/bin'],
282 +    command => "patch -p1 < ${leveldbjni_dir}/leveldbjni.patch",
283 +    unless  => "patch -p1 -R -N --dry-run < ${leveldbjni_dir}/leveldbjni.patch",
284 +    cwd     => $leveldbjni_dir,
285 +    user    => $user,
286 +    require => [Package['patch']],
287 +  } ->
288 +  exec { 'leveldbjni-build':
289 +    command     => "/usr/bin/mvn clean install -P download -P linux64 -P all",
290 +    # Creates requires a fully qualified path which we don't have
291 +    unless      => "/usr/bin/test -d ~${user}/.m2/repository/org/fusesource/leveldbjni/leveldbjni-all",
292 +    environment => $environment,
293 +    cwd         => $leveldbjni_dir,
294 +    user        => $user,
295 +    timeout     => 1200,
296 +    require     => [Package['maven']],
297 +  } ->
298 +  # Can't do this with 'file' type because we need to purge existing package
299 +  # and at the same time don't perform the copy if we've already copied our
300 +  # package.
301 +  exec { 'leveldbjni-copy':
302 +    path    => ['/bin'],
303 +    command => "rm -rf ${target}/system/org/fusesource/leveldbjni && cp -r ~${user}/.m2/repository/org/fusesource/leveldbjni $target/system/org/fusesource/",
304 +    creates => "${target}/system/org/fusesource/leveldbjni/leveldbjni-linux64",
305 +    user    => $user,
306 +  }
307 +}
308 diff --git a/deployment_tasks.yaml b/deployment_tasks.yaml
309 index 6588db3..0fe77af 100644
310 --- a/deployment_tasks.yaml
311 +++ b/deployment_tasks.yaml
312 @@ -17,7 +17,7 @@
313    parameters:
314      puppet_manifest: puppet/manifests/odl-install.pp
315      puppet_modules: puppet/modules:/etc/puppet/modules
316 -    timeout: 720
317 +    timeout: 3600
318  - id: netconfig
319    type: skipped
320  - id: odl-netconfig
321 diff --git a/odl_package/ubuntu/opendaylight b/odl_package/ubuntu/opendaylight
322 index c7f5082..6e5ff7b 100644
323 --- a/odl_package/ubuntu/opendaylight
324 +++ b/odl_package/ubuntu/opendaylight
325 @@ -9,7 +9,7 @@ setgid odl
326  setuid odl
327  
328  env KARAF_HOME="/opt/opendaylight"
329 -env JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
330 +env JAVA_HOME="/usr/lib/jvm/java-7-openjdk-arm64"
331  env JAVA_OPTS="-server -Xms256M -Xmx2048M -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass -XX:MaxPermSize=512M -Dcom.sun.management.jmxremote"
332  env OPTS="-Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true"
333  env MAIN="org.apache.karaf.main.Main"
334 @@ -34,6 +34,6 @@ script
335          fi
336      done
337  
338 -    exec /usr/bin/java $JAVA_OPTS -Djava.endorsed.dirs="${JAVA_ENDORSED_DIRS}" -Djava.ext.dirs="${JAVA_EXT_DIRS}" -Dkaraf.instances="${KARAF_HOME}/instances" -Dkaraf.home="$KARAF_HOME" -Dkaraf.base="$KARAF_BASE" -Dkaraf.data="$KARAF_DATA" -Dkaraf.etc="$KARAF_ETC" -Djava.io.tmpdir="$KARAF_DATA/tmp" -Djava.util.logging.config.file="$KARAF_BASE/etc/java.util.logging.properties" $KARAF_OPTS $OPTS -classpath "$CLASSPATH" $MAIN
339 +    exec ${JAVA_HOME}/bin/java $JAVA_OPTS -Djava.endorsed.dirs="${JAVA_ENDORSED_DIRS}" -Djava.ext.dirs="${JAVA_EXT_DIRS}" -Dkaraf.instances="${KARAF_HOME}/instances" -Dkaraf.home="$KARAF_HOME" -Dkaraf.base="$KARAF_BASE" -Dkaraf.data="$KARAF_DATA" -Dkaraf.etc="$KARAF_ETC" -Djava.io.tmpdir="$KARAF_DATA/tmp" -Djava.util.logging.config.file="$KARAF_BASE/etc/java.util.logging.properties" $KARAF_OPTS $OPTS -classpath "$CLASSPATH" $MAIN
340  
341  end script
342 diff --git a/pre_build_hook b/pre_build_hook
343 index db64e80..b2b97b3 100755
344 --- a/pre_build_hook
345 +++ b/pre_build_hook
346 @@ -41,7 +41,7 @@ fi
347  
348  function cleanup {
349    rm -rf "${TMP_DIR}"
350 -  sed -i -e "s/java-8-openjdk-amd64/java-7-openjdk-amd64/" "${DIR}/odl_package/ubuntu/opendaylight"
351 +  sed -i -e "s/java-8-openjdk-arm64/java-7-openjdk-arm64/" "${DIR}/odl_package/ubuntu/opendaylight"
352  }
353  
354  function download {
355 @@ -87,11 +87,12 @@ function build_pkg {
356        ;;
357      ubuntu)
358        pushd "${DIR}/repositories/${1}/"
359 -      fpm --force -s dir -t deb -m 'mskalski@mirantis.com' --version "${ODL_VERSION_NUMBER}" --description "${ODL_DESCRIPTION}" --prefix /opt/opendaylight --deb-upstart "${DIR}/odl_package/${1}/opendaylight" --after-install "${DIR}/odl_package/${1}/opendaylight-post" --name opendaylight -d "${JAVA_VERSION}" -C "${TMP_DIR}/opendaylight_src"
360 +      fpm --force -s dir -t deb -a arm64 -m 'mskalski@mirantis.com' --version "${ODL_VERSION_NUMBER}" --description "${ODL_DESCRIPTION}" --prefix /opt/opendaylight --deb-upstart "${DIR}/odl_package/${1}/opendaylight" --after-install "${DIR}/odl_package/${1}/opendaylight-post" --name opendaylight -d "${JAVA_VERSION}" -C "${TMP_DIR}/opendaylight_src"
361        fpm --force -s python -t deb -m 'mskalski@mirantis.com' --python-install-lib /usr/lib/python2.7/dist-packages ${TMP_DIR}/networking_odl/setup.py
362        download_dependencies ${1}
363        popd
364 -      add_opnfv_quagga "${DIR}/repositories/${1}/"
365 +      # We are adding arm64 opnfv quagga in our local repository
366 +      #add_opnfv_quagga "${DIR}/repositories/${1}/"
367        ;;
368      *) echo "Not supported system"; exit 1;;
369    esac
370 @@ -103,7 +104,7 @@ cleanup
371  
372  if [ "$USE_JAVA8" = true ]
373  then
374 -  sed -i -e "s/java-7-openjdk-amd64/java-8-openjdk-amd64/" "${DIR}/odl_package/ubuntu/opendaylight"
375 +  sed -i -e "s/java-7-openjdk-arm64/java-8-openjdk-arm64/" "${DIR}/odl_package/ubuntu/opendaylight"
376  fi
377  
378  mkdir -p "${TMP_DIR}"