~ibmcharmers/ibm-wxs-catalog

Owner: kwmonroe
Status: Needs Fixing
Vote: -2 (+2 needed for approval)

CPP?: No
OIL?: No

Migrating from old review queue:

https://bugs.launchpad.net/charms/+bug/1470017


Tests

Substrate Status Results Last Updated
gce FAIL http://juju-ci.vapour.ws/job/charm-bundle-test-gce/160/console 7 months ago
aws FAIL Test Results 7 months ago
lxc FAIL Test Results 7 months ago

Voted: -1
mbruzek wrote 6 months ago
The icon on this charm is invalid and of zero size.
Voted: -1
petevg wrote 4 months ago
Hello,

Thank you for your work on this charm. I came across two small issues in the tests:

1) A linter error (it looks like this is fixed in the source; it just needs to be pushed to the review queue):
tests/01-deploy.py:7:1: E302 expected 2 blank lines, found 1

2) 01-deploy.py needs to be marked as executable ('chmod 755 01-deploy.py'). If it isn't bundletester and related testing tools cannot run it automatically.

Voted: +0
anitanayak wrote 3 months ago
Checked in ibm-wxs-catalog for both trusty and xenial in the below url:
cs:~ibmcharmers/trusty/ibm-wxs-catalog
cs:~ibmcharmers/xenial/ibm-wxs-catalog
Voted: +0
petevg wrote 3 months ago
Hi @anitanayak,

To update the charm in the review queue, you must publish the new versions of the charm to your namespace in the store. That way, the review queue can see and pull the updated code, and we can review it in the queue.

It looks like the version of this charm in the store is still the version I reviewed 20 days ago.

Thank you for you work on this charm, and I look forward to reviewing the new version!

~ PeteVG

Add Comment

Login to comment/vote on this review.


Policy Checklist

Description Unreviewed Pass Fail

General

Must verify that any software installed or utilized is verified as coming from the intended source. petevg
  • Any software installed from the Ubuntu or CentOS default archives satisfies this due to the apt and yum sources including cryptographic signing information.
  • Third party repositories must be listed as a configuration option that can be overridden by the user and not hard coded in the charm itself.
  • Launchpad PPAs are acceptable as the add-apt-repository command retrieves the keys securely.
  • Other third party repositories are acceptable if the signing key is embedded in the charm.
Must provide a means to protect users from known security vulnerabilities in a way consistent with best practices as defined by either operating system policies or upstream documentation. petevg
Basically, this means there must be instructions on how to apply updates if you use software not from distribution channels.
Must have hooks that are idempotent. petevg
Should be built using charm layers. petevg
Should use Juju Resources to deliver required payloads. petevg

Testing and Quality

charm proof must pass without errors or warnings. petevg
Must include passing unit, functional, or integration tests. petevg
Tests must exercise all relations.
Tests must exercise config.
set-config, unset-config, and re-set must be tested as a minimum
Must not use anything infrastructure-provider specific (i.e. querying EC2 metadata service). petevg
Must be self contained unless the charm is a proxy for an existing cloud service, e.g. ec2-elb charm.
Must not use symlinks. petevg
Bundles must only use promulgated charms, they cannot reference charms in personal namespaces. petevg
Must call Juju hook tools (relation-*, unit-*, config-*, etc) without a hard coded path. petevg
Should include a tests.yaml for all integration tests.

Metadata

Must include a full description of what the software does.
Must include a maintainer email address for a team or individual who will be responsive to contact.
Must include a license. Call the file 'copyright' and make sure all files' licenses are specified clearly.
Must be under a Free license.
Must have a well documented and valid README.md.
Must describe the service.
Must describe how it interacts with other services, if applicable.
Must document the interfaces.
Must show how to deploy the charm.
Must define external dependencies, if applicable.
Should link to a recommend production usage bundle and recommended configuration if this differs from the default.
Should reference and link to upstream documentation and best practices.

Security

Must not run any network services using default passwords.
Must verify and validate any external payload
  • Known and understood packaging systems that verify packages like apt, pip, and yum are ok.
  • wget | sh style is not ok.
Should make use of whatever Mandatory Access Control system is provided by the distribution.
Should avoid running services as root.

Source Diff

Inline diff comments 0

No comments yet.

Back to file index

Makefile

 1
--- 
 2
+++ Makefile
 3
@@ -0,0 +1,24 @@
 4
+#!/usr/bin/make
 5
+
 6
+all: lint unit_test
 7
+
 8
+
 9
+.PHONY: clean
10
+clean:
11
+	@rm -rf .tox
12
+
13
+.PHONY: apt_prereqs
14
+apt_prereqs:
15
+	@# Need tox, but don't install the apt version unless we have to (don't want to conflict with pip)
16
+	@which tox >/dev/null || (sudo apt-get install -y python-pip && sudo pip install tox)
17
+
18
+.PHONY: lint
19
+lint: apt_prereqs
20
+	@tox --notest
21
+	@PATH=.tox/py34/bin:.tox/py35/bin flake8 $(wildcard hooks reactive lib unit_tests tests)
22
+	@charm proof
23
+
24
+.PHONY: unit_test
25
+unit_test: apt_prereqs
26
+	@echo Starting tests...
27
+	tox
Back to file index

README.md

  1
--- 
  2
+++ README.md
  3
@@ -0,0 +1,171 @@
  4
+Charm for IBM WebSphere eXtreme Scale (IBM WXS) 8.6.0 for Catalog Service
  5
+
  6
+## Overview
  7
+
  8
+The WebSphere eXtreme Scale licensed program is an elastic, scalable, in-memory data grid. The data grid dynamically caches, partitions, replicates, and manages application data and business logic across multiple servers. WebSphere eXtreme Scale performs massive volumes of transaction processing with high efficiency and linear scalability. With WebSphere eXtreme Scale, you can also get qualities of service such as transactional integrity, high availability, and predictable response times.
  9
+For details on IBM WebSphere eXtreme Scale, as well as information on purchasing, please visit: [Product Page] [wxs-product-page] and at the [Passport Advantage Site] [Passport]. More information available at the [IBM Knowledge Center] [IBM-WXS-Infocenter]
 10
+
 11
+`IBM WebSphere eXtreme Scale Catalog Server`
 12
+
 13
+This charm is using IBM Installation Manager to install IBM WebSphere eXtreme Scale Software. This charm is using ibm-im charm as as base layer to install Installation Manager tool.
 14
+
 15
+## Prerequisites
 16
+
 17
+This charm makes use of resources, a feature only available in Juju 2.0. During deploy or upgrade, you will need to specify the installable package(s)
 18
+required by this charm. Download your licensed IBM WebSphere eXtreme Scale packages from the [Product Page] [WXS-8.6.0-download].
 19
+
 20
+### Packages for Ubuntu on AMD64 (x86_64):
 21
+
 22
+IBM Installation Manager 1.8 (`agent.installer.linux.gtk.x86_64_1.8.3000.20150606_0047.zip`)
 23
+
 24
+IBM WXS 8.6.0 (`WS_XSCALE_V8.6_MP_ML.zip`)
 25
+
 26
+### Packages for Ubuntu on Power (ppc64le):
 27
+
 28
+For Ubuntu on Power, Both Base Package and Fixpack 7 or later version Package required to install.
 29
+
 30
+IBM Installation Manager 1.8 (`agent.installer.linux.gtk.ppc64le_1.8.3000.20150606_0047.zip`)
 31
+
 32
+IBM WXS 8.6.0 (`WS_XSCALE_V8.6_MP_ML.zip`)
 33
+
 34
+IBM WXS 8.6.0.7 (`8.6.0-WS-WXS-FP0000007.zip`)
 35
+
 36
+## Usage
 37
+
 38
+To use this charm, you must agree to the Terms of Use. You can view the full license for `IBM Installation Manager` and `IBM WebSphere eXtreme Scale` products by visiting the [im-license-info](http://www-03.ibm.com/software/sla/sladb.nsf/displaylis/39AFC1C1D485C4E085257E7300548B05?OpenDocument) and [wxs-license-info] [license-info] page.
 39
+
 40
+Search for "IBM WebSphere eXtreme Scale" and choose the license that applies to the version you are using.
 41
+
 42
+
 43
+## Memory and Disk Requirements
 44
+
 45
+Space requirements
 46
+
 47
+    Approximately 1.1 GB of disk space to store the required downloadable parts
 48
+    Approximately 1.1 GB of disk space to unpack the parts
 49
+    Approximately 400 MB of disk space to install the product
 50
+    Approximately 100 MB of space in the tmp directory to run the installation program
 51
+
 52
+WebSphere eXtreme Scale Catalog Server Charm requires 15 GB of root disk to download packages and install the IBM WebSphere eXtreme Scale Catalog Server Software. By default available root disk space is 8GB.
 53
+
 54
+To request a larger root disk, run the following command:
 55
+
 56
+	juju set-constraints root-disk=15G
 57
+
 58
+### Deploy
 59
+
 60
+1. Run the following commands to deploy this charm:
 61
+
 62
+	On x86_64 :
 63
+	
 64
+	    juju deploy ibm-wxs-catalog --resource ibm_im_installer=</path/to/ibm_im_installer.zip> --resource ibm_wxs_base_installer=</path/to/ibm_wxs_base_installer.zip> 
 65
+		
 66
+	On ppc64le :
 67
+	
 68
+		juju deploy ibm-wxs-catalog --resource ibm_im_installer=</path/to/ibm_im_installer.zip> --resource ibm_wxs_base_installer=</path/to/ibm_wxs_base_installer.zip> --resource ibm_wxs_fixpack_installer=</path/to/ibm_wxs_fixpack_installer.zip>
 69
+
 70
+    **Note**: This charm requires acceptance of Terms of Use. When deploying from the Charm Store, these terms will be presented to you for your consideration.  
 71
+         To accept the terms:
 72
+    
 73
+        juju agree ibm-im/1 ibm-wxs/1
 74
+
 75
+
 76
+2. To Expose the IBM WXS Catalog Service to public, run the following command:
 77
+
 78
+		juju expose ibm-wxs-catalog
 79
+
 80
+
 81
+### Upgrade
 82
+
 83
+Once deployed, user can upgrade the existing installation by installing fixpacks:
 84
+
 85
+If user wants to upgrade existing installation of Installtion Manger, run the following command:
 86
+
 87
+	juju attach ibm-wxs-catalog ibm_im_fixpack=</path/to/fixpack.zip>
 88
+
 89
+To upgrade WXS Catalog installation:
 90
+	
 91
+	juju attach ibm-wxs-catalog ibm_wxs_fixpack_installer=</path/to/ibm_wxs_fixpack_installer.zip>
 92
+	
 93
+
 94
+### Verification
 95
+
 96
+After installing IBM WXS Catalog Server, The Catalog server should be Up and Running to get connected to IBM WXS Container and IBM WXS Client Charms.
 97
+Use following command to check if catalog server is running:
 98
+
 99
+    juju run --machine <id> 'ps -ef | grep [c]atalog'
100
+
101
+
102
+## Relating with IBM WXS Container and IBM WXS Client charms
103
+
104
+Install IBM WXS Container and IBM WXS Client Charm. 
105
+
106
+IBM WXS Catalog charm is related to IBM WXS Container and IBM WXS Client charms. 
107
+To add a relation, run the following command:
108
+
109
+	juju add-relation ibm-wxs-catalog ibm-wxs-container
110
+	juju add-relation ibm-wxs-catalog ibm-wxs-client
111
+
112
+The above relation uses `ibm-wxs` interface. When IBM WXS Catalog charm is related to IBM WXS Container and IBM WXS Client charms, user can use the WXS Grid from IBM WXS Client charm.
113
+
114
+### Verification
115
+
116
+After establishing relation with IBM WXS Container and IBM WXS Client charms, user can either access the data grid from .NET Client or Can access IBM WebSphere Server for Application deployment from IBM WXS Client, depending on the topology used in IBM WXS Client.
117
+
118
+To remove the relation, run the following command:
119
+
120
+	juju remove-relation ibm-wxs-catalog ibm-wxs-container
121
+	juju remove-relation ibm-wxs-catalog ibm-wxs-client
122
+
123
+## IBM Installation Manager(IM) Information
124
+
125
+(1) General Information
126
+Details about IM available at [IBM Knowledge Center][Im-info].
127
+
128
+(2) Download Information
129
+Information on procuring IM product is available at the [Product Page][im-product-page]
130
+and at the [Passport Advantage Site][passport].	
131
+
132
+## IBM IBM WebSphere eXtreme Scale Information
133
+
134
+(1) General Information 
135
+
136
+Details about IBM WXS software available at [IBM Knowledge Center] [IBM-WXS-Infocenter].
137
+
138
+Information on procuring WXS product is available at the [Passport Advantage site] [Passport]
139
+
140
+(2) Download Information
141
+
142
+Details about IBM WXS 8.6.0 download available [here] [WXS-8.6.0-download]
143
+
144
+Information about installation of IBM WXS on 'x86_64' and 'ppc64le' based machine available [here] [WXS-Installation]  
145
+
146
+More information about IBM IM Downloadable file and IBM WXS Downloadable files available [here] [IBM-IM-more-info]
147
+
148
+## Contact Information
149
+
150
+For issues with this charm, please contact IBM Juju Support team <jujusupp@us.ibm.com>
151
+
152
+<!-- Links -->
153
+
154
+[IM-info]: http://www-01.ibm.com/support/knowledgecenter/SSDV2W/im_family_welcome.html
155
+
156
+[im-product-page]: http://www-01.ibm.com/support/docview.wss?uid=swg27025142
157
+
158
+[wxs-product-page]: https://www.ibm.com/support/knowledgecenter/SSTVLU_8.6.0/com.ibm.websphere.extremescale.doc/cxsprodoverview.html
159
+
160
+[IBM-WXS-Infocenter]: https://www.ibm.com/support/knowledgecenter/en/SSTVLU_8.6.0/com.ibm.websphere.extremescale.doc/kc_welcome-xs.html
161
+
162
+[WXS-8.6.0-download]: http://www-01.ibm.com/support/docview.wss?uid=swg24033719
163
+
164
+[WXS-Installation]: https://www.ibm.com/support/knowledgecenter/SSTVLU_8.6.0/com.ibm.websphere.extremescale.doc/txsinstalling.html
165
+
166
+[Passport]: http://www-01.ibm.com/software/passportadvantage/
167
+
168
+[IBM-IM-more-info]: http://www-01.ibm.com/support/docview.wss?uid=swg24038380
169
+
170
+[WXS-download-links]: https://www-947.ibm.com/support/entry/myportal/all_download_links/websphere/websphere_extreme_scale?productContext=-966955061
171
+
172
+[WXS-Support-link]: https://support-pilot.podc.sl.edst.ibm.com/support/home/product/P838994E69185S66/WebSphere_eXtreme_Scale?redir=auto_overlay&redirURL=https:%2F%2Fwww-947.ibm.com%2Fsupport%2Fentry%2Fmyportal%2Fproduct%2Fwebsphere%2Fwebsphere_extreme_scale%3FproductContext%3D-966955061%26redir%3Dno
173
+
174
+[license-info]: http://www-01.ibm.com/common/ssi/cgi-bin/ssialias?htmlfid=897/ENUS212-370&infotype=AN&subtype=CA&appname=wwwsearch#h2-tcx
Back to file index

bin/layer_option

 1
--- 
 2
+++ bin/layer_option
 3
@@ -0,0 +1,24 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+import sys
 7
+sys.path.append('lib')
 8
+
 9
+import argparse
10
+from charms.layer import options
11
+
12
+
13
+parser = argparse.ArgumentParser(description='Access layer options.')
14
+parser.add_argument('section',
15
+                    help='the section, or layer, the option is from')
16
+parser.add_argument('option',
17
+                    help='the option to access')
18
+
19
+args = parser.parse_args()
20
+value = options(args.section).get(args.option, '')
21
+if isinstance(value, bool):
22
+    sys.exit(0 if value else 1)
23
+elif isinstance(value, list):
24
+    for val in value:
25
+        print(val)
26
+else:
27
+    print(value)
Back to file index

config.yaml

 1
--- 
 2
+++ config.yaml
 3
@@ -0,0 +1,55 @@
 4
+"options":
 5
+  "curl_url":
 6
+    "type": "string"
 7
+    "default": ""
 8
+    "description": |
 9
+      Location of the IBM product installation file(s). This should be a URL
10
+      that curl can use to download files. Multiple URLs should be separated
11
+      by a space. NOTE: cryptographic verification is required and must be
12
+      specified as part of the URL query string with the key a valid hash
13
+      algorithms md5, sha256, or sha512, and the the checksum value itself
14
+      (http://<url>?[md5|sha256|sha512]=<checksum>).
15
+      For example:
16
+        'http://example.com/file.tgz?sha256=<sum>'
17
+        'sftp://example.com/file1.tgz?md5=<sum> ftp://example.com/file2.tgz?md5=<sum>'
18
+  "curl_opts":
19
+    "type": "string"
20
+    "default": ""
21
+    "description": |
22
+      The options passed to the 'curl' command when fetching files from
23
+      curl_url. For example:
24
+        '-u <user:password>'
25
+  "license_accepted":
26
+    "type": "boolean"
27
+    "default": !!bool "false"
28
+    "description": |
29
+      Some IBM charms require acceptance of a license before installation
30
+      can proceed. If required, setting this option to True indicates that you
31
+      have read and accepted the IBM terms and conditions found in the license
32
+      file referenced by the charm.
33
+  "extra_packages":
34
+    "description": "Space separated list of extra deb packages to install.\n"
35
+    "type": "string"
36
+    "default": ""
37
+  "package_status":
38
+    "default": "install"
39
+    "type": "string"
40
+    "description": "The status of service-affecting packages will be set to this value\
41
+      \ in the dpkg database. Valid values are \"install\" and \"hold\".\n"
42
+  "install_sources":
43
+    "description": "List of extra apt sources, per charm-helpers standard format (a\
44
+      \ yaml list of strings encoded as a string). Each source may be either a line\
45
+      \ that can be added directly to sources.list(5), or in the form ppa:<user>/<ppa-name>\
46
+      \ for adding Personal Package Archives, or a distribution component to enable.\n"
47
+    "type": "string"
48
+    "default": ""
49
+  "install_keys":
50
+    "description": "List of signing keys for install_sources package sources, per\
51
+      \ charmhelpers standard format (a yaml list of strings encoded as a string).\
52
+      \ The keys should be the full ASCII armoured GPG public keys. While GPG key\
53
+      \ ids are also supported and looked up on a keyserver, operators should be aware\
54
+      \ that this mechanism is insecure. null can be used if a standard package signing\
55
+      \ key is used that will already be installed on the machine, and for PPA sources\
56
+      \ where the package signing key is securely retrieved from Launchpad.\n"
57
+    "type": "string"
58
+    "default": ""
Back to file index

hooks/config-changed

 1
--- 
 2
+++ hooks/config-changed
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/hook.template

 1
--- 
 2
+++ hooks/hook.template
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/install

 1
--- 
 2
+++ hooks/install
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/leader-elected

 1
--- 
 2
+++ hooks/leader-elected
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/leader-settings-changed

 1
--- 
 2
+++ hooks/leader-settings-changed
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/relations/ibm-wxs/README.md

 1
--- 
 2
+++ hooks/relations/ibm-wxs/README.md
 3
@@ -0,0 +1,28 @@
 4
+Overview
 5
+-----------
 6
+
 7
+This interface layer handles the communication between `IBM WXS Catalog` and `IBM WXS Container` or `IBM WXS Catalog` and `IBM WXS Client` charms.
 8
+The provider end of this interface provides the WXS Catalog service. The consumer/Requires part will be the IBM WXS Container and IBM WXS Client, which want the IBM WXS Catalog Server Ip Address and Port information to fetch the Data Grid.
 9
+
10
+
11
+Usage
12
+------
13
+
14
+#### Provides
15
+IBM WXS catalog Server product will provide this interface. This interface layer will set the following states, as appropriate:
16
+
17
+ - `{relation_name}.available`: The relation is established, IBM WXS Catalog is ready to send it's Ip Address and Port information. At this point, the charm waits for Provider charm to send IP Address and port.
18
+	- `set_wxs_catalog_details()` : Sets IP Address and Port of the Catalog Server once the Server started successfully.
19
+
20
+#### Requires
21
+
22
+Consumer charms `IBM WXS Container` and `IBM WXS Client` will require this interface to connect to WXS Catalog so that they can connect to Catalog Server. 
23
+This interface layer will set the following states, as appropriate:
24
+
25
+- `{relation_name}.available` : The consumer charm has been related to a IBM WXS Catalog provider charm. 
26
+- `{relation_name}.ready` : IBM WXS Container or IBM WXS Client is now ready to connect to WXS Catalog to fetch Data Grid. 
27
+	The Http Server charm can access the configuration details using the below methods:
28
+
29
+    - `get_wxs_catalog_port()` - returns the port of the Catalog Server that listens.
30
+    - `get_wxs_catalog_ip()` - returns running ip of the Catalog Server.
31
+   
Back to file index

hooks/relations/ibm-wxs/interface.yaml

1
--- 
2
+++ hooks/relations/ibm-wxs/interface.yaml
3
@@ -0,0 +1,4 @@
4
+name: ibm-wxs
5
+summary: Basic WXS interface
6
+version: 1
7
+maintainer: "IBM Juju Support Team <jujusupp@us.ibm.com>"
Back to file index

hooks/relations/ibm-wxs/provides.py

 1
--- 
 2
+++ hooks/relations/ibm-wxs/provides.py
 3
@@ -0,0 +1,73 @@
 4
+from charms.reactive import hook
 5
+from charms.reactive import RelationBase
 6
+from charms.reactive import scopes
 7
+
 8
+
 9
+class WXSProvides(RelationBase):
10
+    # Every unit connecting will get the same information
11
+    scope = scopes.SERVICE
12
+    # convenient way to provide accessor methods
13
+    # auto_accessors = ['wxs_catalog_ip', 'wxs_catalog_port']
14
+
15
+    @hook('{provides:ibm-wxs}-relation-joined')
16
+    def joined(self):
17
+        conversation = self.conversation()
18
+        conversation.set_state('{relation_name}.available')
19
+        print("In joined hook in ibm-wxs interface")
20
+
21
+    @hook('{provides:ibm-wxs}-relation-changed')
22
+    def changed(self):
23
+        conversation = self.conversation()
24
+        conversation.set_state('{relation_name}.available')
25
+        print("In changed hook in ibm-wxs interface")
26
+
27
+    @hook('{provides:ibm-wxs}-relation-departed')
28
+    def departed(self):
29
+        conversation = self.conversation()
30
+        conversation.remove_state('{relation_name}.available')
31
+        print("In departed hook in ibm-wxs interface")
32
+
33
+    def dismiss(self, service):
34
+        conversation = self.conversation(service)
35
+        conversation.remove_state('{relation_name}.available')
36
+        print("In dismissed for service", service)
37
+
38
+    def reset_states(self, service):
39
+        conversation = self.conversation(service)
40
+        conversation.remove_state('{relation_name}.available')
41
+
42
+    def set_wxs_catalog_details(self, service, wxs_catalog_ip,
43
+                                wxs_catalog_port):
44
+        conversation = self.conversation(service)
45
+        print("In set_wxs_catalog_details for service", service)
46
+        conversation.set_remote(data={
47
+            'wxs_catalog_ip': wxs_catalog_ip,
48
+            'wxs_catalog_port': wxs_catalog_port
49
+        })
50
+
51
+    #    def wxs_catalog_ip(self):
52
+    #    """
53
+    #    Return a list of services requesting databases.
54
+    #    """
55
+    #    wxs_catalog_ip = []
56
+    #    for conversation in self.conversations():
57
+    #        wxs_catalog_ip.append(conversation.scope)
58
+    #    return wxs_catalog_ip
59
+#
60
+#    def wxs_catalog_port(self):
61
+#        """
62
+#        Return a list of services requesting databases.
63
+#        """
64
+#        wxs_catalog_port = []
65
+#        for conversation in self.conversations():
66
+#            wxs_catalog_port.append(conversation.scope)
67
+#        return wxs_catalog_port
68
+
69
+    def services(self):
70
+        """
71
+        Return a list of services requesting Catalog.
72
+        """
73
+        service = []
74
+        for conversation in self.conversations():
75
+            service.append(conversation.scope)
76
+        return service
Back to file index

hooks/relations/ibm-wxs/requires.py

 1
--- 
 2
+++ hooks/relations/ibm-wxs/requires.py
 3
@@ -0,0 +1,43 @@
 4
+# Licensed under the Apache License, Version 2.0 (the "License");
 5
+# you may not use this file except in compliance with the License.
 6
+# You may obtain a copy of the License at
 7
+#
 8
+#     http://www.apache.org/licenses/LICENSE-2.0
 9
+#
10
+# Unless required by applicable law or agreed to in writing, software
11
+# distributed under the License is distributed on an "AS IS" BASIS,
12
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+# See the License for the specific language governing permissions and
14
+# limitations under the License.
15
+# from charmhelpers.core import hookenv
16
+from charms.reactive import hook
17
+from charms.reactive import RelationBase
18
+from charms.reactive import scopes
19
+
20
+
21
+class WXSRequires(RelationBase):
22
+    scope = scopes.GLOBAL
23
+
24
+    auto_accessors = ['wxs_catalog_ip', 'wxs_catalog_port']
25
+
26
+    @hook('{requires:ibm-wxs}-relation-joined')
27
+    def joined(self):
28
+        self.set_state('{relation_name}.available')
29
+
30
+    @hook('{requires:ibm-wxs}-relation-changed')
31
+    def changed(self):
32
+        print("Status is ibm-wxs.available in requires")
33
+        if str(self.get_remote('wxs_catalog_port')) != "None":
34
+            self.set_state('{relation_name}.ready')
35
+            print("Status is relation_name.available in requires")
36
+
37
+    @hook('{requires:ibm-wxs}-relation-departed')
38
+    def departed(self):
39
+        self.remove_state('{relation_name}.available')
40
+        self.remove_state('{relation_name}.ready')
41
+
42
+    def get_wxs_catalog_port(self):
43
+        return self.get_remote('wxs_catalog_port')
44
+
45
+    def get_wxs_catalog_ip(self):
46
+        return self.get_remote('wxs_catalog_ip')
Back to file index

hooks/start

 1
--- 
 2
+++ hooks/start
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/stop

 1
--- 
 2
+++ hooks/stop
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/update-status

 1
--- 
 2
+++ hooks/update-status
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/upgrade-charm

 1
--- 
 2
+++ hooks/upgrade-charm
 3
@@ -0,0 +1,28 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import os
 8
+import sys
 9
+sys.path.append('lib')
10
+
11
+# This is an upgrade-charm context, make sure we install latest deps
12
+if not os.path.exists('wheelhouse/.upgrade'):
13
+    open('wheelhouse/.upgrade', 'w').close()
14
+    if os.path.exists('wheelhouse/.bootstrapped'):
15
+        os.unlink('wheelhouse/.bootstrapped')
16
+else:
17
+    os.unlink('wheelhouse/.upgrade')
18
+
19
+from charms.layer import basic
20
+basic.bootstrap_charm_deps()
21
+basic.init_config_states()
22
+
23
+
24
+# This will load and run the appropriate @hook and other decorated
25
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
26
+# and $CHARM_DIR/hooks/relations.
27
+#
28
+# See https://jujucharms.com/docs/stable/authors-charm-building
29
+# for more information on this pattern.
30
+from charms.reactive import main
31
+main()
Back to file index

hooks/wxsgrid-relation-broken

 1
--- 
 2
+++ hooks/wxsgrid-relation-broken
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/wxsgrid-relation-changed

 1
--- 
 2
+++ hooks/wxsgrid-relation-changed
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/wxsgrid-relation-departed

 1
--- 
 2
+++ hooks/wxsgrid-relation-departed
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

hooks/wxsgrid-relation-joined

 1
--- 
 2
+++ hooks/wxsgrid-relation-joined
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

layer.yaml

 1
--- 
 2
+++ layer.yaml
 3
@@ -0,0 +1,26 @@
 4
+"repo": "bzr+ssh://bazaar.launchpad.net/~ibmcharmers/charms/trusty/layer-ibm-wxs-catalog/trunk/"
 5
+"includes":
 6
+- "layer:ibm-base"
 7
+- "layer:basic"
 8
+- "layer:apt"
 9
+- "layer:leadership"
10
+- "layer:basic"
11
+- "layer:ibm-im"
12
+- "interface:ibm-wxs"
13
+"options":
14
+  "basic":
15
+    "packages":
16
+    - "unzip"
17
+    - "curl"
18
+    - "unzip"
19
+    "use_venv": !!bool "false"
20
+    "include_system_packages": !!bool "false"
21
+  "ibm-im":
22
+    "silent": !!bool "true"
23
+    "ibm_im_package": ""
24
+  "ibm-wxs-catalog": {}
25
+  "apt":
26
+    "packages": []
27
+  "leadership": {}
28
+  "ibm-base": {}
29
+"is": "ibm-wxs-catalog"
Back to file index

lib/charms/__init__.py

1
--- 
2
+++ lib/charms/__init__.py
3
@@ -0,0 +1,2 @@
4
+from pkgutil import extend_path
5
+__path__ = extend_path(__path__, __name__)
Back to file index

lib/charms/apt.py

  1
--- 
  2
+++ lib/charms/apt.py
  3
@@ -0,0 +1,182 @@
  4
+# Copyright 2015-2016 Canonical Ltd.
  5
+#
  6
+# This file is part of the Apt layer for Juju.
  7
+#
  8
+# This program is free software: you can redistribute it and/or modify
  9
+# it under the terms of the GNU General Public License version 3, as
 10
+# published by the Free Software Foundation.
 11
+#
 12
+# This program is distributed in the hope that it will be useful, but
 13
+# WITHOUT ANY WARRANTY; without even the implied warranties of
 14
+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 15
+# PURPOSE.  See the GNU General Public License for more details.
 16
+#
 17
+# You should have received a copy of the GNU General Public License
 18
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 19
+
 20
+'''
 21
+charms.reactive helpers for dealing with deb packages.
 22
+
 23
+Add apt package sources using add_source(). Queue deb packages for
 24
+installation with install(). Configure and work with your software
 25
+once the apt.installed.{packagename} state is set.
 26
+'''
 27
+import itertools
 28
+import subprocess
 29
+
 30
+from charmhelpers import fetch
 31
+from charmhelpers.core import hookenv, unitdata
 32
+from charms import reactive
 33
+
 34
+
 35
+__all__ = ['add_source', 'update', 'queue_install', 'install_queued',
 36
+           'installed', 'purge', 'ensure_package_status']
 37
+
 38
+
 39
+def add_source(source, key=None):
 40
+    '''Add an apt source.
 41
+
 42
+    Sets the apt.needs_update state.
 43
+
 44
+    A source may be either a line that can be added directly to
 45
+    sources.list(5), or in the form ppa:<user>/<ppa-name> for adding
 46
+    Personal Package Archives, or a distribution component to enable.
 47
+
 48
+    The package signing key should be an ASCII armoured GPG key. While
 49
+    GPG key ids are also supported, the retrieval mechanism is insecure.
 50
+    There is no need to specify the package signing key for PPAs or for
 51
+    the main Ubuntu archives.
 52
+    '''
 53
+    # Maybe we should remember which sources have been added already
 54
+    # so we don't waste time re-adding them. Is this time significant?
 55
+    fetch.add_source(source, key)
 56
+    reactive.set_state('apt.needs_update')
 57
+
 58
+
 59
+def queue_install(packages, options=None):
 60
+    """Queue one or more deb packages for install.
 61
+
 62
+    The `apt.installed.{name}` state is set once the package is installed.
 63
+
 64
+    If a package has already been installed it will not be reinstalled.
 65
+
 66
+    If a package has already been queued it will not be requeued, and
 67
+    the install options will not be changed.
 68
+
 69
+    Sets the apt.queued_installs state.
 70
+    """
 71
+    if isinstance(packages, str):
 72
+        packages = [packages]
 73
+    # Filter installed packages.
 74
+    store = unitdata.kv()
 75
+    queued_packages = store.getrange('apt.install_queue.', strip=True)
 76
+    packages = {package: options for package in packages
 77
+                if not (package in queued_packages or
 78
+                        reactive.helpers.is_state('apt.installed.' + package))}
 79
+    if packages:
 80
+        unitdata.kv().update(packages, prefix='apt.install_queue.')
 81
+        reactive.set_state('apt.queued_installs')
 82
+
 83
+
 84
+def installed():
 85
+    '''Return the set of deb packages completed install'''
 86
+    return set(state.split('.', 2)[2] for state in reactive.bus.get_states()
 87
+               if state.startswith('apt.installed.'))
 88
+
 89
+
 90
+def purge(packages):
 91
+    """Purge one or more deb packages from the system"""
 92
+    fetch.apt_purge(packages, fatal=True)
 93
+    store = unitdata.kv()
 94
+    store.unsetrange(packages, prefix='apt.install_queue.')
 95
+    for package in packages:
 96
+        reactive.remove_state('apt.installed.{}'.format(package))
 97
+
 98
+
 99
+def update():
100
+    """Update the apt cache.
101
+
102
+    Removes the apt.needs_update state.
103
+    """
104
+    status_set(None, 'Updating apt cache')
105
+    fetch.apt_update(fatal=True)  # Friends don't let friends set fatal=False
106
+    reactive.remove_state('apt.needs_update')
107
+
108
+
109
+def install_queued():
110
+    '''Installs queued deb packages.
111
+
112
+    Removes the apt.queued_installs state and sets the apt.installed state.
113
+
114
+    On failure, sets the unit's workload state to 'blocked' and returns
115
+    False. Package installs remain queued.
116
+
117
+    On success, sets the apt.installed.{packagename} state for each
118
+    installed package and returns True.
119
+    '''
120
+    store = unitdata.kv()
121
+    queue = sorted((options, package)
122
+                   for package, options in store.getrange('apt.install_queue.',
123
+                                                          strip=True).items())
124
+
125
+    installed = set()
126
+    for options, batch in itertools.groupby(queue, lambda x: x[0]):
127
+        packages = [b[1] for b in batch]
128
+        try:
129
+            status_set(None, 'Installing {}'.format(','.join(packages)))
130
+            fetch.apt_install(packages, options, fatal=True)
131
+            store.unsetrange(packages, prefix='apt.install_queue.')
132
+            installed.update(packages)
133
+        except subprocess.CalledProcessError:
134
+            status_set('blocked',
135
+                       'Unable to install packages {}'
136
+                       .format(','.join(packages)))
137
+            return False  # Without setting reactive state.
138
+
139
+    for package in installed:
140
+        reactive.set_state('apt.installed.{}'.format(package))
141
+
142
+    reactive.remove_state('apt.queued_installs')
143
+    return True
144
+
145
+
146
+def ensure_package_status():
147
+    '''Hold or unhold packages per the package_status configuration option.
148
+
149
+    All packages installed using this module and handlers are affected.
150
+
151
+    An mechanism may be added in the future to override this for a
152
+    subset of installed packages.
153
+    '''
154
+    packages = installed()
155
+    if not packages:
156
+        return
157
+    config = hookenv.config()
158
+    package_status = config['package_status']
159
+    changed = reactive.helpers.data_changed('apt.package_status',
160
+                                            (package_status, sorted(packages)))
161
+    if changed:
162
+        if package_status == 'hold':
163
+            hookenv.log('Holding packages {}'.format(','.join(packages)))
164
+            fetch.apt_hold(packages)
165
+        else:
166
+            hookenv.log('Unholding packages {}'.format(','.join(packages)))
167
+            fetch.apt_unhold(packages)
168
+    reactive.remove_state('apt.needs_hold')
169
+
170
+
171
+def status_set(state, message):
172
+    """Set the unit's workload status.
173
+
174
+    Set state == None to keep the same state and just change the message.
175
+    """
176
+    if state is None:
177
+        state = hookenv.status_get()[0]
178
+        if state == 'unknown':
179
+            state = 'maintenance'  # Guess
180
+    if state in ('error', 'blocked'):
181
+        lvl = hookenv.WARNING
182
+    else:
183
+        lvl = hookenv.INFO
184
+    hookenv.status_set(state, message)
185
+    hookenv.log('{}: {}'.format(state, message), lvl)
Back to file index

lib/charms/layer/__init__.py

 1
--- 
 2
+++ lib/charms/layer/__init__.py
 3
@@ -0,0 +1,21 @@
 4
+import os
 5
+
 6
+
 7
+class LayerOptions(dict):
 8
+    def __init__(self, layer_file, section=None):
 9
+        import yaml  # defer, might not be available until bootstrap
10
+        with open(layer_file) as f:
11
+            layer = yaml.safe_load(f.read())
12
+        opts = layer.get('options', {})
13
+        if section and section in opts:
14
+            super(LayerOptions, self).__init__(opts.get(section))
15
+        else:
16
+            super(LayerOptions, self).__init__(opts)
17
+
18
+
19
+def options(section=None, layer_file=None):
20
+    if not layer_file:
21
+        base_dir = os.environ.get('CHARM_DIR', os.getcwd())
22
+        layer_file = os.path.join(base_dir, 'layer.yaml')
23
+
24
+    return LayerOptions(layer_file, section)
Back to file index

lib/charms/layer/basic.py

  1
--- 
  2
+++ lib/charms/layer/basic.py
  3
@@ -0,0 +1,159 @@
  4
+import os
  5
+import sys
  6
+import shutil
  7
+import platform
  8
+from glob import glob
  9
+from subprocess import check_call
 10
+
 11
+from charms.layer.execd import execd_preinstall
 12
+
 13
+
 14
+def bootstrap_charm_deps():
 15
+    """
 16
+    Set up the base charm dependencies so that the reactive system can run.
 17
+    """
 18
+    # execd must happen first, before any attempt to install packages or
 19
+    # access the network, because sites use this hook to do bespoke
 20
+    # configuration and install secrets so the rest of this bootstrap
 21
+    # and the charm itself can actually succeed. This call does nothing
 22
+    # unless the operator has created and populated $CHARM_DIR/exec.d.
 23
+    execd_preinstall()
 24
+    # ensure that $CHARM_DIR/bin is on the path, for helper scripts
 25
+    os.environ['PATH'] += ':%s' % os.path.join(os.environ['CHARM_DIR'], 'bin')
 26
+    venv = os.path.abspath('../.venv')
 27
+    vbin = os.path.join(venv, 'bin')
 28
+    vpip = os.path.join(vbin, 'pip')
 29
+    vpy = os.path.join(vbin, 'python')
 30
+    if os.path.exists('wheelhouse/.bootstrapped'):
 31
+        from charms import layer
 32
+        cfg = layer.options('basic')
 33
+        if cfg.get('use_venv') and '.venv' not in sys.executable:
 34
+            # activate the venv
 35
+            os.environ['PATH'] = ':'.join([vbin, os.environ['PATH']])
 36
+            reload_interpreter(vpy)
 37
+        return
 38
+    # bootstrap wheelhouse
 39
+    if os.path.exists('wheelhouse'):
 40
+        with open('/root/.pydistutils.cfg', 'w') as fp:
 41
+            # make sure that easy_install also only uses the wheelhouse
 42
+            # (see https://github.com/pypa/pip/issues/410)
 43
+            charm_dir = os.environ['CHARM_DIR']
 44
+            fp.writelines([
 45
+                "[easy_install]\n",
 46
+                "allow_hosts = ''\n",
 47
+                "find_links = file://{}/wheelhouse/\n".format(charm_dir),
 48
+            ])
 49
+        apt_install(['python3-pip', 'python3-setuptools', 'python3-yaml'])
 50
+        from charms import layer
 51
+        cfg = layer.options('basic')
 52
+        # include packages defined in layer.yaml
 53
+        apt_install(cfg.get('packages', []))
 54
+        # if we're using a venv, set it up
 55
+        if cfg.get('use_venv'):
 56
+            if not os.path.exists(venv):
 57
+                distname, version, series = platform.linux_distribution()
 58
+                if series in ('precise', 'trusty'):
 59
+                    apt_install(['python-virtualenv'])
 60
+                else:
 61
+                    apt_install(['virtualenv'])
 62
+                cmd = ['virtualenv', '-ppython3', '--never-download', venv]
 63
+                if cfg.get('include_system_packages'):
 64
+                    cmd.append('--system-site-packages')
 65
+                check_call(cmd)
 66
+            os.environ['PATH'] = ':'.join([vbin, os.environ['PATH']])
 67
+            pip = vpip
 68
+        else:
 69
+            pip = 'pip3'
 70
+            # save a copy of system pip to prevent `pip3 install -U pip`
 71
+            # from changing it
 72
+            if os.path.exists('/usr/bin/pip'):
 73
+                shutil.copy2('/usr/bin/pip', '/usr/bin/pip.save')
 74
+        # need newer pip, to fix spurious Double Requirement error:
 75
+        # https://github.com/pypa/pip/issues/56
 76
+        check_call([pip, 'install', '-U', '--no-index', '-f', 'wheelhouse',
 77
+                    'pip'])
 78
+        # install the rest of the wheelhouse deps
 79
+        check_call([pip, 'install', '-U', '--no-index', '-f', 'wheelhouse'] +
 80
+                   glob('wheelhouse/*'))
 81
+        if not cfg.get('use_venv'):
 82
+            # restore system pip to prevent `pip3 install -U pip`
 83
+            # from changing it
 84
+            if os.path.exists('/usr/bin/pip.save'):
 85
+                shutil.copy2('/usr/bin/pip.save', '/usr/bin/pip')
 86
+                os.remove('/usr/bin/pip.save')
 87
+        os.remove('/root/.pydistutils.cfg')
 88
+        # flag us as having already bootstrapped so we don't do it again
 89
+        open('wheelhouse/.bootstrapped', 'w').close()
 90
+        # Ensure that the newly bootstrapped libs are available.
 91
+        # Note: this only seems to be an issue with namespace packages.
 92
+        # Non-namespace-package libs (e.g., charmhelpers) are available
 93
+        # without having to reload the interpreter. :/
 94
+        reload_interpreter(vpy if cfg.get('use_venv') else sys.argv[0])
 95
+
 96
+
 97
+def reload_interpreter(python):
 98
+    """
 99
+    Reload the python interpreter to ensure that all deps are available.
100
+
101
+    Newly installed modules in namespace packages sometimes seemt to
102
+    not be picked up by Python 3.
103
+    """
104
+    os.execle(python, python, sys.argv[0], os.environ)
105
+
106
+
107
+def apt_install(packages):
108
+    """
109
+    Install apt packages.
110
+
111
+    This ensures a consistent set of options that are often missed but
112
+    should really be set.
113
+    """
114
+    if isinstance(packages, (str, bytes)):
115
+        packages = [packages]
116
+
117
+    env = os.environ.copy()
118
+
119
+    if 'DEBIAN_FRONTEND' not in env:
120
+        env['DEBIAN_FRONTEND'] = 'noninteractive'
121
+
122
+    cmd = ['apt-get',
123
+           '--option=Dpkg::Options::=--force-confold',
124
+           '--assume-yes',
125
+           'install']
126
+    check_call(cmd + packages, env=env)
127
+
128
+
129
+def init_config_states():
130
+    import yaml
131
+    from charmhelpers.core import hookenv
132
+    from charms.reactive import set_state
133
+    from charms.reactive import toggle_state
134
+    config = hookenv.config()
135
+    config_defaults = {}
136
+    config_defs = {}
137
+    config_yaml = os.path.join(hookenv.charm_dir(), 'config.yaml')
138
+    if os.path.exists(config_yaml):
139
+        with open(config_yaml) as fp:
140
+            config_defs = yaml.safe_load(fp).get('options', {})
141
+            config_defaults = {key: value.get('default')
142
+                               for key, value in config_defs.items()}
143
+    for opt in config_defs.keys():
144
+        if config.changed(opt):
145
+            set_state('config.changed')
146
+            set_state('config.changed.{}'.format(opt))
147
+        toggle_state('config.set.{}'.format(opt), config.get(opt))
148
+        toggle_state('config.default.{}'.format(opt),
149
+                     config.get(opt) == config_defaults[opt])
150
+    hookenv.atexit(clear_config_states)
151
+
152
+
153
+def clear_config_states():
154
+    from charmhelpers.core import hookenv, unitdata
155
+    from charms.reactive import remove_state
156
+    config = hookenv.config()
157
+    remove_state('config.changed')
158
+    for opt in config.keys():
159
+        remove_state('config.changed.{}'.format(opt))
160
+        remove_state('config.set.{}'.format(opt))
161
+        remove_state('config.default.{}'.format(opt))
162
+    unitdata.kv().flush()
Back to file index

lib/charms/layer/execd.py

  1
--- 
  2
+++ lib/charms/layer/execd.py
  3
@@ -0,0 +1,138 @@
  4
+# Copyright 2014-2016 Canonical Limited.
  5
+#
  6
+# This file is part of layer-basic, the reactive base layer for Juju.
  7
+#
  8
+# charm-helpers is free software: you can redistribute it and/or modify
  9
+# it under the terms of the GNU Lesser General Public License version 3 as
 10
+# published by the Free Software Foundation.
 11
+#
 12
+# charm-helpers is distributed in the hope that it will be useful,
 13
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
 14
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15
+# GNU Lesser General Public License for more details.
 16
+#
 17
+# You should have received a copy of the GNU Lesser General Public License
 18
+# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
 19
+
 20
+# This module may only import from the Python standard library.
 21
+import os
 22
+import sys
 23
+import subprocess
 24
+import time
 25
+
 26
+'''
 27
+execd/preinstall
 28
+
 29
+It is often necessary to configure and reconfigure machines
 30
+after provisioning, but before attempting to run the charm.
 31
+Common examples are specialized network configuration, enabling
 32
+of custom hardware, non-standard disk partitioning and filesystems,
 33
+adding secrets and keys required for using a secured network.
 34
+
 35
+The reactive framework's base layer invokes this mechanism as
 36
+early as possible, before any network access is made or dependencies
 37
+unpacked or non-standard modules imported (including the charms.reactive
 38
+framework itself).
 39
+
 40
+Operators needing to use this functionality may branch a charm and
 41
+create an exec.d directory in it. The exec.d directory in turn contains
 42
+one or more subdirectories, each of which contains an executable called
 43
+charm-pre-install and any other required resources. The charm-pre-install
 44
+executables are run, and if successful, state saved so they will not be
 45
+run again.
 46
+
 47
+    $CHARM_DIR/exec.d/mynamespace/charm-pre-install
 48
+
 49
+An alternative to branching a charm is to compose a new charm that contains
 50
+the exec.d directory, using the original charm as a layer,
 51
+
 52
+A charm author could also abuse this mechanism to modify the charm
 53
+environment in unusual ways, but for most purposes it is saner to use
 54
+charmhelpers.core.hookenv.atstart().
 55
+'''
 56
+
 57
+
 58
+def default_execd_dir():
 59
+    return os.path.join(os.environ['CHARM_DIR'], 'exec.d')
 60
+
 61
+
 62
+def execd_module_paths(execd_dir=None):
 63
+    """Generate a list of full paths to modules within execd_dir."""
 64
+    if not execd_dir:
 65
+        execd_dir = default_execd_dir()
 66
+
 67
+    if not os.path.exists(execd_dir):
 68
+        return
 69
+
 70
+    for subpath in os.listdir(execd_dir):
 71
+        module = os.path.join(execd_dir, subpath)
 72
+        if os.path.isdir(module):
 73
+            yield module
 74
+
 75
+
 76
+def execd_submodule_paths(command, execd_dir=None):
 77
+    """Generate a list of full paths to the specified command within exec_dir.
 78
+    """
 79
+    for module_path in execd_module_paths(execd_dir):
 80
+        path = os.path.join(module_path, command)
 81
+        if os.access(path, os.X_OK) and os.path.isfile(path):
 82
+            yield path
 83
+
 84
+
 85
+def execd_sentinel_path(submodule_path):
 86
+    module_path = os.path.dirname(submodule_path)
 87
+    execd_path = os.path.dirname(module_path)
 88
+    module_name = os.path.basename(module_path)
 89
+    submodule_name = os.path.basename(submodule_path)
 90
+    return os.path.join(execd_path,
 91
+                        '.{}_{}.done'.format(module_name, submodule_name))
 92
+
 93
+
 94
+def execd_run(command, execd_dir=None, stop_on_error=True, stderr=None):
 95
+    """Run command for each module within execd_dir which defines it."""
 96
+    if stderr is None:
 97
+        stderr = sys.stdout
 98
+    for submodule_path in execd_submodule_paths(command, execd_dir):
 99
+        # Only run each execd once. We cannot simply run them in the
100
+        # install hook, as potentially storage hooks are run before that.
101
+        # We cannot rely on them being idempotent.
102
+        sentinel = execd_sentinel_path(submodule_path)
103
+        if os.path.exists(sentinel):
104
+            continue
105
+
106
+        try:
107
+            subprocess.check_call([submodule_path], stderr=stderr,
108
+                                  universal_newlines=True)
109
+            with open(sentinel, 'w') as f:
110
+                f.write('{} ran successfully {}\n'.format(submodule_path,
111
+                                                          time.ctime()))
112
+                f.write('Removing this file will cause it to be run again\n')
113
+        except subprocess.CalledProcessError as e:
114
+            # Logs get the details. We can't use juju-log, as the
115
+            # output may be substantial and exceed command line
116
+            # length limits.
117
+            print("ERROR ({}) running {}".format(e.returncode, e.cmd),
118
+                  file=stderr)
119
+            print("STDOUT<<EOM", file=stderr)
120
+            print(e.output, file=stderr)
121
+            print("EOM", file=stderr)
122
+
123
+            # Unit workload status gets a shorter fail message.
124
+            short_path = os.path.relpath(submodule_path)
125
+            block_msg = "Error ({}) running {}".format(e.returncode,
126
+                                                       short_path)
127
+            try:
128
+                subprocess.check_call(['status-set', 'blocked', block_msg],
129
+                                      universal_newlines=True)
130
+                if stop_on_error:
131
+                    sys.exit(0)  # Leave unit in blocked state.
132
+            except Exception:
133
+                pass  # We care about the exec.d/* failure, not status-set.
134
+
135
+            if stop_on_error:
136
+                sys.exit(e.returncode or 1)  # Error state for pre-1.24 Juju
137
+
138
+
139
+def execd_preinstall(execd_dir=None):
140
+    """Run charm-pre-install for each module within execd_dir."""
141
+    execd_run('charm-pre-install', execd_dir=execd_dir)
Back to file index

lib/charms/leadership.py

 1
--- 
 2
+++ lib/charms/leadership.py
 3
@@ -0,0 +1,58 @@
 4
+# Copyright 2015-2016 Canonical Ltd.
 5
+#
 6
+# This file is part of the Leadership Layer for Juju.
 7
+#
 8
+# This program is free software: you can redistribute it and/or modify
 9
+# it under the terms of the GNU General Public License version 3, as
10
+# published by the Free Software Foundation.
11
+#
12
+# This program is distributed in the hope that it will be useful, but
13
+# WITHOUT ANY WARRANTY; without even the implied warranties of
14
+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
+# PURPOSE.  See the GNU General Public License for more details.
16
+#
17
+# You should have received a copy of the GNU General Public License
18
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
+
20
+from charmhelpers.core import hookenv
21
+from charmhelpers.core import unitdata
22
+
23
+from charms import reactive
24
+from charms.reactive import not_unless
25
+
26
+
27
+__all__ = ['leader_get', 'leader_set']
28
+
29
+
30
+@not_unless('leadership.is_leader')
31
+def leader_set(settings=None, **kw):
32
+    '''Change leadership settings, per charmhelpers.core.hookenv.leader_set.
33
+
34
+    The leadership.set.{key} reactive state will be set while the
35
+    leadership hook environment setting remains set.
36
+
37
+    Changed leadership settings will set the leadership.changed.{key}
38
+    and leadership.changed states. These states will remain set until
39
+    the following hook.
40
+
41
+    These state changes take effect immediately on the leader, and
42
+    in future hooks run on non-leaders. In this way both leaders and
43
+    non-leaders can share handlers, waiting on these states.
44
+    '''
45
+    settings = settings or {}
46
+    settings.update(kw)
47
+    previous = unitdata.kv().getrange('leadership.settings.', strip=True)
48
+
49
+    for key, value in settings.items():
50
+        if value != previous.get(key):
51
+            reactive.set_state('leadership.changed.{}'.format(key))
52
+            reactive.set_state('leadership.changed')
53
+        reactive.helpers.toggle_state('leadership.set.{}'.format(key),
54
+                                      value is not None)
55
+    hookenv.leader_set(settings)
56
+    unitdata.kv().update(settings, prefix='leadership.settings.')
57
+
58
+
59
+def leader_get(attribute=None):
60
+    '''Return leadership settings, per charmhelpers.core.hookenv.leader_get.'''
61
+    return hookenv.leader_get(attribute)
Back to file index

metadata.yaml

 1
--- 
 2
+++ metadata.yaml
 3
@@ -0,0 +1,39 @@
 4
+"name": "ibm-wxs-catalog"
 5
+"summary": "IBM WebSphere eXtreme Scale"
 6
+"maintainer": "IBM Juju Support Team <jujusupp@us.ibm.com>"
 7
+"description": |
 8
+  IBM WebSphere eXtreme Scale is an elastic, scalable, in-memory data grid (IMDG). It is designed to help you handle exponential growth of transactions. With WebSphere eXtreme Scale, you can expect an enhanced quality of service in high-performance computing environments.
 9
+"tags":
10
+- "ibm"
11
+- "im"
12
+- "ibm"
13
+- "ibm"
14
+- "wxs-catalog"
15
+- "in-memory data grid"
16
+- "workload_management"
17
+- "wxs-catalog-master"
18
+"provides":
19
+  "wxsgrid":
20
+    "interface": "ibm-wxs"
21
+"min-juju-version": "2.0-beta1"
22
+"resources":
23
+  "ibm_im_installer":
24
+    "type": "file"
25
+    "filename": "ibm_im_installer.zip"
26
+    "description": "Installation Manager installer archive"
27
+  "ibm_im_fixpack":
28
+    "type": "file"
29
+    "filename": "ibm_im_fixpack.zip"
30
+    "description": "Installation Manager fix pack archive"
31
+  "ibm_wxs_base_installer":
32
+    "type": "file"
33
+    "filename": "ibm_wxs_base_installer.zip"
34
+    "description": "WXS  Base installer archive"
35
+  "ibm_wxs_fixpack_installer":
36
+    "type": "file"
37
+    "filename": "ibm_wxs_fixpack_installer.zip"
38
+    "description": "WXS Fixpack installer archive"
39
+"subordinate": !!bool "false"
40
+"terms":
41
+- "ibm-im/1"
42
+- "ibm-wxs/1"
Back to file index

reactive/apt.py

  1
--- 
  2
+++ reactive/apt.py
  3
@@ -0,0 +1,131 @@
  4
+# Copyright 2015-2016 Canonical Ltd.
  5
+#
  6
+# This file is part of the Apt layer for Juju.
  7
+#
  8
+# This program is free software: you can redistribute it and/or modify
  9
+# it under the terms of the GNU General Public License version 3, as
 10
+# published by the Free Software Foundation.
 11
+#
 12
+# This program is distributed in the hope that it will be useful, but
 13
+# WITHOUT ANY WARRANTY; without even the implied warranties of
 14
+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 15
+# PURPOSE.  See the GNU General Public License for more details.
 16
+#
 17
+# You should have received a copy of the GNU General Public License
 18
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 19
+
 20
+'''
 21
+charms.reactive helpers for dealing with deb packages.
 22
+
 23
+Add apt package sources using add_source(). Queue deb packages for
 24
+installation with install(). Configure and work with your software
 25
+once the apt.installed.{packagename} state is set.
 26
+'''
 27
+import subprocess
 28
+
 29
+from charmhelpers import fetch
 30
+from charmhelpers.core import hookenv
 31
+from charmhelpers.core.hookenv import WARNING
 32
+from charms import layer
 33
+from charms import reactive
 34
+from charms.reactive import when, when_not
 35
+
 36
+import charms.apt
 37
+
 38
+
 39
+@when('apt.needs_update')
 40
+def update():
 41
+    charms.apt.update()
 42
+
 43
+
 44
+@when('apt.queued_installs')
 45
+@when_not('apt.needs_update')
 46
+def install_queued():
 47
+    charms.apt.install_queued()
 48
+
 49
+
 50
+@when_not('apt.queued_installs')
 51
+def ensure_package_status():
 52
+    charms.apt.ensure_package_status()
 53
+
 54
+
 55
+def filter_installed_packages(packages):
 56
+    # Don't use fetch.filter_installed_packages, as it depends on python-apt
 57
+    # and not available if the basic layer's use_site_packages option is off
 58
+    # TODO: Move this to charm-helpers.fetch
 59
+    cmd = ['dpkg-query', '--show', r'--showformat=${Package}\n']
 60
+    installed = set(subprocess.check_output(cmd,
 61
+                                            universal_newlines=True).split())
 62
+    return set(packages) - installed
 63
+
 64
+
 65
+def clear_removed_package_states():
 66
+    """On hook startup, clear install states for removed packages."""
 67
+    removed = filter_installed_packages(charms.apt.installed())
 68
+    if removed:
 69
+        hookenv.log('{} missing packages ({})'.format(len(removed),
 70
+                                                      ','.join(removed)),
 71
+                    WARNING)
 72
+        for package in removed:
 73
+            reactive.remove_state('apt.installed.{}'.format(package))
 74
+
 75
+
 76
+def configure_sources():
 77
+    """Add user specified package sources from the service configuration.
 78
+
 79
+    See charmhelpers.fetch.configure_sources for details.
 80
+    """
 81
+    config = hookenv.config()
 82
+
 83
+    # We don't have enums, so we need to validate this ourselves.
 84
+    package_status = config.get('package_status')
 85
+    if package_status not in ('hold', 'install'):
 86
+        charms.apt.status_set('blocked',
 87
+                              'Unknown package_status {}'
 88
+                              ''.format(package_status))
 89
+        # Die before further hooks are run. This isn't very nice, but
 90
+        # there is no other way to inform the operator that they have
 91
+        # invalid configuration.
 92
+        raise SystemExit(0)
 93
+
 94
+    sources = config.get('install_sources')
 95
+    keys = config.get('install_keys')
 96
+    if reactive.helpers.data_changed('apt.configure_sources', (sources, keys)):
 97
+        fetch.configure_sources(update=False,
 98
+                                sources_var='install_sources',
 99
+                                keys_var='install_keys')
100
+        reactive.set_state('apt.needs_update')
101
+
102
+    extra_packages = sorted(config.get('extra_packages', '').split())
103
+    if extra_packages:
104
+        charms.apt.queue_install(extra_packages)
105
+
106
+
107
+def queue_layer_packages():
108
+    """Add packages listed in build-time layer options."""
109
+    # Both basic and apt layer. basic layer will have already installed
110
+    # its defined packages, but rescheduling it here gets the apt layer
111
+    # state set and they will pinned as any other apt layer installed
112
+    # package.
113
+    opts = layer.options()
114
+    for section in ['basic', 'apt']:
115
+        if section in opts and 'packages' in opts[section]:
116
+            charms.apt.queue_install(opts[section]['packages'])
117
+
118
+
119
+# Per https://github.com/juju-solutions/charms.reactive/issues/33,
120
+# this module may be imported multiple times so ensure the
121
+# initialization hook is only registered once. I have to piggy back
122
+# onto the namespace of a module imported before reactive discovery
123
+# to do this.
124
+if not hasattr(reactive, '_apt_registered'):
125
+    # We need to register this to run every hook, not just during install
126
+    # and config-changed, to protect against race conditions. If we don't
127
+    # do this, then the config in the hook environment may show updates
128
+    # to running hooks well before the config-changed hook has been invoked
129
+    # and the intialization provided an opertunity to be run.
130
+    hookenv.atstart(hookenv.log, 'Initializing Apt Layer')
131
+    hookenv.atstart(clear_removed_package_states)
132
+    hookenv.atstart(configure_sources)
133
+    hookenv.atstart(queue_layer_packages)
134
+    reactive._apt_registered = True
Back to file index

reactive/ibm-base.sh

  1
--- 
  2
+++ reactive/ibm-base.sh
  3
@@ -0,0 +1,107 @@
  4
+#!/bin/bash
  5
+source charms.reactive.sh
  6
+set -e
  7
+
  8
+
  9
+# Utility function to verify a downloaded resource
 10
+# :param: file name
 11
+# :param: checksum type
 12
+# :param: checksum value
 13
+function verify_curl_resource() {
 14
+  local FILE=$1
 15
+  local TYPE=$2
 16
+  local EXPECTED_SUM=$3
 17
+  local CALCULATED_SUM=""
 18
+  local PROG=""
 19
+
 20
+  if [ ! -r ${FILE} ]; then
 21
+    status-set blocked "ibm-base: could not read ${FILE}"
 22
+    juju-log "Could not verify the downloaded resource. File could not be read: ${FILE}"
 23
+  fi
 24
+
 25
+  # Set our checksum utility based on the requested type
 26
+  case "${TYPE}" in
 27
+    md5)
 28
+      PROG='md5sum'
 29
+      ;;
 30
+    sha256)
 31
+      PROG='sha256sum'
 32
+      ;;
 33
+    sha512)
 34
+      PROG='sha512sum'
 35
+      ;;
 36
+    *)
 37
+      status-set blocked "ibm-base: checksum type must be md5, sha215, or sha512"
 38
+      juju-log "Could not verify the downloaded resource ${FILE}. Unknown checksum type: ${TYPE}"
 39
+      return 1
 40
+  esac
 41
+
 42
+  CALCULATED_SUM=`${PROG} ${FILE} | awk '{print $1}'`
 43
+  if [ "${CALCULATED_SUM}" = "${EXPECTED_SUM}" ]; then
 44
+    juju-log "Checksum verified for ${FILE}."
 45
+    return 0
 46
+  else
 47
+    status-set blocked "ibm-base: checksums did not match"
 48
+    juju-log "Checksum mismatch for ${FILE}. Expected ${EXPECTED_SUM}, got ${CALCULATED_SUM}"
 49
+    return 1
 50
+  fi
 51
+}
 52
+
 53
+
 54
+# Fetch curl resources if a URL is configured
 55
+@when 'config.set.curl_url'
 56
+@when_any 'config.new.curl_url' 'config.changed.curl_url' 'config.new.curl_opts' 'config.changed.curl_opts'
 57
+function fetch_curl_resource() {
 58
+  local ARCHIVE_DIR="${CHARM_DIR}/files/archives"
 59
+  local CURL_URL=$(config-get 'curl_url')
 60
+  local CURL_OPTS=$(config-get 'curl_opts')
 61
+
 62
+  status-set maintenance "ibm-base: fetching resource(s)"
 63
+
 64
+  mkdir -p ${ARCHIVE_DIR}
 65
+  cd ${ARCHIVE_DIR}
 66
+  # Multiple URLs may be separated by a space, so loop.
 67
+  for URL_STRING in ${CURL_URL}
 68
+  do
 69
+    # For each URL_STRING, set the url, checksum type, and checksum value.
 70
+    local URL=${URL_STRING%%\?*}        # string before the first '?'
 71
+    local FILE_NAME=${URL##*\/}         # string after the last '/'
 72
+    local SUM_STRING=${URL_STRING#*\?}  # string after the first '?'
 73
+    local SUM_TYPE=${SUM_STRING%%\=*}   # string before the first '='
 74
+    local SUM_VALUE=${SUM_STRING#*\=}   # string after the first '='
 75
+
 76
+    if [ -z ${FILE_NAME} ]; then
 77
+      FILE_NAME="juju-${RANDOM}"
 78
+    fi
 79
+    curl --silent --show-error ${CURL_OPTS} -o ${FILE_NAME} ${URL}
 80
+
 81
+    # Verify our resource checksum. If this fails, let verify_resource log
 82
+    # the reason and exit successfully. Exiting non-zero would fail the hook,
 83
+    # so return 0 and simply inform the user that verification failed.
 84
+    verify_curl_resource ${FILE_NAME} ${SUM_TYPE} ${SUM_VALUE} || return 0
 85
+  done
 86
+  cd -
 87
+
 88
+  set_state 'ibm-base.curl.resource.fetched'
 89
+  status-set active "ibm-base: curl resource(s) fetched"
 90
+  juju-log 'Curl resource fetched'
 91
+}
 92
+
 93
+
 94
+# Handle license acceptance
 95
+@when 'config.changed.license_accepted'
 96
+function check_license_acceptance() {
 97
+  local LIC_ACCEPTED=$(config-get 'license_accepted')
 98
+
 99
+  # compare lowercase LIC_ACCEPTED (requires bash > 4)
100
+  if [ "${LIC_ACCEPTED,,}" = "true" ]; then
101
+    set_state 'ibm-base.license.accepted'
102
+    juju-log 'License accepted'
103
+  else
104
+    remove_state 'ibm-base.license.accepted'
105
+    juju-log 'License NOT accepted'
106
+  fi
107
+}
108
+
109
+# Main reactive entry point
110
+reactive_handler_main
Back to file index

reactive/ibm-im.sh

  1
--- 
  2
+++ reactive/ibm-im.sh
  3
@@ -0,0 +1,187 @@
  4
+#!/bin/bash
  5
+set -e
  6
+
  7
+source charms.reactive.sh
  8
+ARCHITECTURE=`uname -m`
  9
+
 10
+# Installation Manager install path
 11
+IM_INSTALL_PATH="/opt/IBM/InstallationManager"
 12
+
 13
+@when_not 'ibm-im.installed'
 14
+function install_ibm_im(){
 15
+      # Fail fast if we're on an unsupported arch
 16
+      if [ "$ARCHITECTURE" != "x86_64" -a  "$ARCHITECTURE" != "ppc64le" ]; then
 17
+            juju-log "IBM IM: only supported on x86_64 or ppc64le platforms"
 18
+            status-set blocked "unsupported architecture"
 19
+            exit 1
 20
+      fi
 21
+
 22
+      # Get the installable resource
 23
+      juju-log "IBM IM: fetching the ibm_im_installer resource"
 24
+      status-set maintenance "fetching the ibm_im_installer resource"
 25
+      cfg_im_pkg_name=`resource-get 'ibm_im_installer' || echo unavailable`
 26
+
 27
+      # If we don't have a package, report blocked status; we can't proceed.
 28
+      if [ "$cfg_im_pkg_name" = "unavailable" ]; then
 29
+        juju-log "IBM IM: missing required ibm_im_installer resource"
 30
+        status-set blocked "missing required ibm_im_installer resource"
 31
+        exit 0
 32
+      fi
 33
+
 34
+      juju-log "IBM IM: using $cfg_im_pkg_name as the ibm_im_installer resource"
 35
+      ARCHIVE_DIR=`dirname $cfg_im_pkg_name`
 36
+
 37
+      # Extract the installer contents
 38
+      if [ -f  $cfg_im_pkg_name ]; then
 39
+           juju-log "IBM IM: extracting the ibm_im_installer resource"
 40
+           status-set maintenance "extracting the ibm_im_installer resource"
 41
+           if [ -f $ARCHIVE_DIR/userinstc ]; then
 42
+                 juju-log "IBM IM: ibm_im_installer resource already extracted"
 43
+           else
 44
+                 cd $ARCHIVE_DIR
 45
+                 if ! unzip $cfg_im_pkg_name; then
 46
+                      juju-log "IBM IM: Unable to extract the ibm_im_installer resource"
 47
+                      # Remove corrupt archive file
 48
+                      status-set blocked "ibm_im_installer resource is corrupt"
 49
+                      rm -rf $ARCHIVE_DIR
 50
+                      exit 0
 51
+                 else
 52
+                      juju-log "IBM IM: ibm_im_installer resource extracted successfully"
 53
+                 fi
 54
+           fi
 55
+      fi
 56
+
 57
+      # Do the actual IBM IM install
 58
+      if [ -f  $ARCHIVE_DIR/userinstc ]; then
 59
+        juju-log "IBM IM: starting installation."
 60
+        status-set maintenance "installing ibm-im"
 61
+        cp $ARCHIVE_DIR/install.xml $ARCHIVE_DIR/silent_install.xml
 62
+        sed -i "2 a \<profile kind='self' installLocation='$IM_INSTALL_PATH' id='IBM Installation Manager'>\n <data key='eclipseLocation' value='$IM_INSTALL_PATH' />\n</profile>" $ARCHIVE_DIR/silent_install.xml
 63
+        if $ARCHIVE_DIR/userinstc -input $ARCHIVE_DIR/silent_install.xml -acceptlicense; then
 64
+            set_state 'ibm-im.installed'
 65
+            status-set active "ready"
 66
+        else
 67
+            juju-log "IBM IM: error while installing"
 68
+            exit 1
 69
+        fi
 70
+      else
 71
+        juju-log "IBM IM: installer was not found."
 72
+        status-set blocked "installation failed"
 73
+        exit 1
 74
+      fi
 75
+}
 76
+
 77
+@when 'ibm-im.installed'
 78
+@when_not 'ibm-im.updated'
 79
+function install_ibm_im_fixpack(){
 80
+    # Get the fixpack resource
 81
+    juju-log "IBM IM: fetching the ibm_im_fixpack resource"
 82
+    status-set maintenance "fetching the ibm_im_fixpack resource"
 83
+    ibm_im_fp_package=`resource-get 'ibm_im_fixpack' || echo unavailable`
 84
+
 85
+    # If we don't have a fixpack, just exit successfully; there's nothing to do.
 86
+    if [ "$ibm_im_fp_package" = "unavailable" ]; then
 87
+      juju-log "IBM IM: no ibm_im_fixpack to install"
 88
+      status-set active "ready"
 89
+      exit 0
 90
+    fi
 91
+
 92
+    # Currently, there is no way to make a resource optional, so something
 93
+    # must be uploaded to the charm store, even if it's a dummy archive.
 94
+    # If we detect the fixpack is just a placeholder (because we created an
 95
+    # empty placeholder in the store), exit just like we do with a missing
 96
+    # fixpack resource.
 97
+    ibm_im_fp_empty=`file $ibm_im_fp_package | { grep -q empty && echo "True"; } || echo "False"`
 98
+    if [ "$ibm_im_fp_empty" = "True" ]; then
 99
+      juju-log "IBM IM: no ibm_im_fixpack to install"
100
+      status-set active "ready"
101
+      exit 0
102
+    fi
103
+
104
+    juju-log "IBM IM: using $ibm_im_fp_package as the ibm_im_fixpack resource"
105
+    ARCHIVE_DIR=`dirname $ibm_im_fp_package`
106
+
107
+    # Extract the fixpack contents
108
+    if [ -f $ibm_im_fp_package ]; then
109
+        juju-log "IBM IM: extracting the ibm_im_fixpack resource"
110
+        status-set maintenance "extracting the ibm_im_fixpack resource"
111
+        if [ -f $ARCHIVE_DIR/userinstc ]; then
112
+              juju-log "IBM IM: ibm_im_fixpack resource already extracted"
113
+        else
114
+              cd $ARCHIVE_DIR
115
+              if ! unzip $ibm_im_fp_package; then
116
+                      juju-log "IBM IM: Unable to extract the ibm_im_fixpack resource"
117
+                      # Remove corrupt archive file
118
+                      status-set blocked "ibm_im_fixpack resource is corrupt"
119
+                      rm  -rf $ARCHIVE_DIR
120
+                      exit 0
121
+              else
122
+                      juju-log "IBM IM: ibm_im_fixpack resource extracted successfully"
123
+              fi
124
+        fi
125
+    fi
126
+
127
+    # Do the actual IBM IM fixpack install
128
+    if [ -f $ARCHIVE_DIR/userinstc ]; then
129
+        juju-log "IBM IM: starting fixpack installation."
130
+        status-set maintenance "installing fixpack"
131
+        cp $ARCHIVE_DIR/install.xml $ARCHIVE_DIR/silent_install.xml
132
+        sed -i "2 a \<profile kind='self' installLocation='$IM_INSTALL_PATH' id='IBM Installation Manager'>\n <data key='eclipseLocation' value='$IM_INSTALL_PATH' />\n</profile>" $ARCHIVE_DIR/silent_install.xml
133
+        if $ARCHIVE_DIR/userinstc -input $ARCHIVE_DIR/silent_install.xml -acceptlicense; then
134
+             set_state 'ibm-im.updated'
135
+             status-set active "ready"
136
+        else
137
+             juju-log "IBM IM: error while installing the fixpack."
138
+             exit 1
139
+        fi
140
+    else
141
+        juju-log "IBM_IM: Fix pack installer was not found."
142
+        status-set blocked "fixpack installation failed"
143
+        exit 1
144
+   fi
145
+}
146
+
147
+@hook 'upgrade-charm'
148
+function check_fixpack(){
149
+    # The upgrade-charm hook will fire when a new resource is pushed for this
150
+    # charm. This is a good time to determine if we need to deal with a new
151
+    # fixpack.
152
+    if ! charms.reactive is_state 'ibm-im.updated'; then
153
+        # If there is no prior fixpack installed (because ibm-im.updated is not
154
+        # set), do nothing since install-ibm-im-fixpack will handle that case.
155
+        juju-log "IBM IM: no fixpack has been installed; nothing to upgrade."
156
+        exit 0
157
+    else
158
+        # If we have a fixpack already (because ibm-im.updated is set),
159
+        # we should fetch the latest fixpack and determine if it is new.
160
+        #  - If it is new, set our states so install-ibm-im-fixpack is called again
161
+        #  - If it is not new, do nothing
162
+        juju-log "IBM IM: scanning for new fixpacks to install"
163
+        ARCHIVE_DIR="$CHARM_DIR/../resources/ibm_im_fixpack"
164
+        CUR_FIXPACK="$ARCHIVE_DIR/ibm_im_fixpack.zip"
165
+
166
+        # Sum any existing fixpack to determine if we have a new one
167
+        if [ -f $CUR_FIXPACK ]; then
168
+            CUR_MD5=`md5sum "$CUR_FIXPACK" | awk '{print $1}'`
169
+            # Calling resource-get here will fetch the fixpack resource.
170
+            NEW_FIXPACK=`resource-get 'ibm_im_fixpack' || echo unavailable`
171
+            if [ "$NEW_FIXPACK" = "unavailable" ]; then
172
+                juju-log "IBM IM: no fixpack to install"
173
+            else
174
+                NEW_MD5=`md5sum "$NEW_FIXPACK" | awk '{print $1}'`
175
+                # If sums don't match, we have a new fp. Configure states so
176
+                # we re-run install-ibm-im-fixpack().
177
+                if [ "$CUR_MD5" != "$NEW_MD5" ]; then
178
+                    juju-log "IBM IM: new fixpack detected ($CUR_FIXPACK with $CUR_MD5 versus $NEW_FIXPACK with $NEW_MD5)"
179
+                    rm -rf $ARCHIVE_DIR
180
+                    remove_state 'ibm-im.updated'
181
+                else
182
+                    juju-log "IBM IM: no new fixpack to install"
183
+                fi
184
+            fi
185
+        fi
186
+    fi
187
+}
188
+
189
+
190
+reactive_handler_main
Back to file index

reactive/ibm-wxs-catalog.sh

  1
--- 
  2
+++ reactive/ibm-wxs-catalog.sh
  3
@@ -0,0 +1,358 @@
  4
+#!/bin/bash
  5
+set -ex
  6
+
  7
+source charms.reactive.sh
  8
+
  9
+ARCHITECTURE=`uname -m`
 10
+IM_INSTALL_PATH=/opt/IBM/InstallationManager
 11
+WXS_INSTALL_PATH=/opt/ibm/WXS
 12
+private_address=`unit-get private-address`
 13
+wxs_catalog_port=2809
 14
+
 15
+#Check the System Arch
 16
+function check_arch() {
 17
+	#Check the architecture before installing the product
 18
+	if [ "$ARCHITECTURE" != "x86_64" -a "$ARCHITECTURE" != "ppc64le" ]; then
 19
+		juju-log "check_arch: Unsupported platform. IBM WXS installed with this Charm supports only on x86_64 or ppc64le platform."
 20
+		status-set blocked "IBM WXS Catalog: Platform not supported"
 21
+	 	exit 1
 22
+	fi
 23
+}
 24
+
 25
+#start wxs server
 26
+function start_wxs_catalog(){ 
 27
+	juju-log "start_wxs_catalog: Inside start_wxs_catalog server"
 28
+	if [ -d $WXS_INSTALL_PATH/ObjectGrid/bin/ ]; then
 29
+		set +e
 30
+		serverstareted=`ps -ef | grep "[c]atalogService"`
 31
+		set -e
 32
+		if [ -z "$serverstareted" ]; then
 33
+			juju-log "start_wxs_catalog: Starting catalog server"
 34
+			if ! $WXS_INSTALL_PATH/ObjectGrid/bin/startXsServer.sh cs0 -catalogServiceEndPoints cs0:$private_address:6600:6601 -listenerPort $wxs_catalog_port -listenerHost $private_address
 35
+			then
 36
+				juju-log "start_wxs_catalog: Error while starting catalogServer"
 37
+				status-set blocked "IBM WXS Catalog: Error while starting catalogServer"
 38
+				return 1
 39
+			else
 40
+				juju-log "start_wxs_catalog: catalogServer started successfully"
 41
+				set_state 'ibm-wxs-catalog-server.started'
 42
+				status-set maintenance "IBM WXS Catalog: WXS Catalog server started successfully"
 43
+				return 0
 44
+			fi
 45
+		fi
 46
+	 else
 47
+            status-set blocked "IBM WXS Catalog: No server to start"
 48
+	    return 1
 49
+	 fi
 50
+}
 51
+
 52
+#stop wxs server
 53
+function stop_wxs_catalog() {
 54
+juju-log "Start: stop_wxs_catalog"
 55
+set +e
 56
+ps -ef | grep "[c]atalogService"
 57
+set -e
 58
+if [ $? == 0 ]; then
 59
+	if ! $WXS_INSTALL_PATH/ObjectGrid/bin/xscmd.sh -c teardown -sl cs0 --catalogEndPoints "$private_address":2809 -f
 60
+	then
 61
+		juju-log "stop_wxs_catalog: Error while stopping catalogServer"
 62
+		status-set blocked "IBM WXS Catalog: Error while stopping catalogServer"
 63
+		return 1
 64
+	else
 65
+		juju-log "stop_wxs_catalog: catalogServer stopped successfully"
 66
+		remove_state 'ibm-wxs-catalog-server.started'
 67
+		status-set maintenance "IBM WXS Catalog: WXS Catalog server stopped successfully"
 68
+		return 0
 69
+	fi
 70
+else
 71
+	juju-log "stop_wxs_catalog: catalogServer is not running"
 72
+	status-set maintenance "IBM WXS Catalog: catalogServer is not running"
 73
+	return 0
 74
+fi
 75
+}
 76
+
 77
+
 78
+#Install WXS Catalog base package
 79
+@when 'ibm-im.installed'
 80
+@when_not 'ibm-wxs-catalog.installed' 'ibm-wxs-catalog-base-ppc64le.extracted'
 81
+function install-wxs-catalog(){
 82
+	
 83
+	#check arch supported
 84
+	juju-log "install-wxs-catalog: calling check_arch function"
 85
+	check_arch
 86
+	#add ip address to /etc/hosts
 87
+	juju-log "install-wxs-catalog: Checking etc/hosts file."
 88
+	private_address=`unit-get private-address`
 89
+	juju-log "private_address : $private_address"
 90
+	cd /etc
 91
+	if grep -q "$private_address" hosts
 92
+	then
 93
+		juju-log "install-wxs-catalog: Host file already updated"
 94
+	else
 95
+		juju-log "install-wxs-catalog: Updating Host file"
 96
+		echo "$private_address `hostname`" >> /etc/hosts
 97
+	fi
 98
+
 99
+
100
+	#check if downloaded package is present in ${CHARM_DIR}/../resources
101
+	if [ -d $CHARM_DIR/../resources/WXS_BASE/ ]; then
102
+		juju-log "install-wxs-catalog: Base Package Extracted already"
103
+		status-set maintenance "IBM WXS Catalog: Base Package Extracted already"
104
+	fi
105
+	if [ ! -d $CHARM_DIR/../resources/WXS_BASE/ ]; then
106
+		juju-log "install-wxs-catalog: fetching the ibm_wxs_base_installer resource"
107
+		status-set maintenance "IBM WXS Catalog: fetching the ibm_wxs_base_installer resource"
108
+		cfg_wxs_base_pkg_name=`resource-get 'ibm_wxs_base_installer' || echo unavailable`
109
+
110
+		ibm_wxs_pkg_isempty=`file $cfg_wxs_base_pkg_name | { grep -q empty && echo "True"; } || echo "False"`
111
+	
112
+		if [ "$cfg_wxs_base_pkg_name" = "unavailable" ]; then
113
+			juju-log "install-wxs-catalog: missing required ibm_wxs_base_installer resource"
114
+			status-set blocked "IBM WXS Catalog: missing required ibm_wxs_base_installer resource"
115
+			exit 0
116
+		fi
117
+		if [ "$ibm_wxs_pkg_isempty" = "True" ]; then
118
+			juju-log "install-wxs-catalog: missing required ibm_wxs_base_installer resource, found empty packages"
119
+			status-set blocked "IBM WXS Catalog: missing required ibm_wxs_base_installer resource, provide actual ibm_wxs_base_installer resources."
120
+			exit 0 
121
+		fi
122
+
123
+		if [ -f $cfg_wxs_base_pkg_name ]; then
124
+			ARCHIVE_DIR=`dirname $cfg_wxs_base_pkg_name`
125
+			juju-log "install-wxs-catalog: extracting the ibm_wxs_base_installer resources"
126
+			status-set maintenance "IBM WXS Catalog: extracting the ibm_wxs_base_installer resource"
127
+			if [ ! -d $ARCHIVE_DIR/../WXS_BASE ]; then
128
+				mkdir $ARCHIVE_DIR/../WXS_BASE
129
+			fi
130
+			if ! unzip ${cfg_wxs_base_pkg_name} -d ${ARCHIVE_DIR}/../WXS_BASE
131
+			then
132
+				juju-log "install-wxs-catalog: Unable to extract the WXS package content. Verify whether the package is corrupt."
133
+				status-set blocked "IBM WXS Catalog: IBM WXS package is corrupt"
134
+				rm -rf $ARCHIVE_DIR/../WXS_BASE 
135
+				exit 0
136
+			else
137
+				juju-log "install-wxs-catalog: Extracted wxs_base package"
138
+				status-set maintenance "IBM WXS Catalog: Extracted wxs_base package"
139
+			fi
140
+		fi
141
+	fi
142
+	#Install WXS package
143
+	juju-log "install_wxs_base: WXS Base Installation started"
144
+	if [ "$ARCHITECTURE" == "x86_64" ];then
145
+		if ! $IM_INSTALL_PATH/eclipse/tools/imcl install com.ibm.websphere.WXS.v86 -acceptLicense -installationDirectory $WXS_INSTALL_PATH -repositories ${CHARM_DIR}/../resources/WXS_BASE/WXS_8600
146
+		then
147
+			juju-log "install_wxs_base: Error while installing WXS Base"
148
+			status-set blocked "IBM WXS Catalog: install wxs catalog: Error while installing WXS Base"
149
+			exit 1
150
+		else
151
+			juju-log "install_wxs_base: WXS Base installed successfully"
152
+			status-set maintenance "IBM WXS Catalog: WXS Base installed successfully"
153
+			set_state 'ibm-wxs-catalog.installed'
154
+		fi	
155
+	elif [ "$ARCHITECTURE" == "ppc64le" ];then
156
+		if [ -d ${CHARM_DIR}/../resources/WXS_BASE/WXS_8600 ]; then
157
+			juju-log "install-wxs-catalog: For PPC64LE Platform need both wxs_base and wxs_fixpack packages"
158
+			status-set blocked "IBM WXS Catalog: Both WXS Base and Fixpack are required to install IBM WXS on ppc64le. Missing required ibm_wxs_fixpack_installer resource"
159
+			set_state 'ibm-wxs-catalog-base-ppc64le.extracted'
160
+			exit 0
161
+		fi	
162
+	fi
163
+}
164
+
165
+
166
+#Install WXS Catalog fixpack package
167
+@when_any 'ibm-wxs-catalog.installed' 'ibm-wxs-catalog-base-ppc64le.extracted'
168
+@when_not 'ibm-wxs-catalog.updated'
169
+function install-wxs-catalog-fixpack(){
170
+	
171
+	#check if downloaded package is present in ${CHARM_DIR}/files/archives
172
+	juju-log "install-wxs-catalog-fixpack: inside ibm_wxs_fixpack_installer resource"
173
+	status-set maintenance "IBM WXS Catalog: fetching the ibm_wxs_fixpack_installer resource"
174
+	cfg_wxs_fixpack_pkg_name=`resource-get 'ibm_wxs_fixpack_installer' || echo unavailable`
175
+
176
+	ibm_wxs_fixpack_isempty=`file $cfg_wxs_fixpack_pkg_name | { grep -q empty && echo "True"; } || echo "False"`
177
+
178
+	if [ "$cfg_wxs_fixpack_pkg_name" = "unavailable" ]; then
179
+		if [ "$ARCHITECTURE" == "ppc64le" ]; then
180
+			juju-log "install-wxs-catalog-fixpack: missing required ibm_wxs_fixpack_installer resource"
181
+			status-set blocked "IBM WXS Catalog: missing required ibm_wxs_fixpack_installer resource for ppc64le platform"
182
+			exit 0	
183
+		elif [ "$ARCHITECTURE" == "x86_64" ]; then
184
+			juju-log "install-wxs-catalog-fixpack: no ibm_wxs_fixpack_installer packages to install"
185
+			status-set active "IBM WXS Catalog: IBM WXS Catalog is Ready"
186
+			return 0
187
+		fi
188
+			
189
+	fi
190
+	if [ "$ibm_wxs_fixpack_isempty" = "True" ]; then
191
+		if [ "$ARCHITECTURE" == "ppc64le" ]; then
192
+			juju-log "install-wxs-catalog-fixpack: missing required ibm_wxs_fixpack_installer resource, found empty packages"
193
+			status-set blocked "IBM WXS Catalog: missing required ibm_wxs_fixpack_installer resource, provide actual ibm_wxs_fixpack_installer resources."
194
+			exit 0	
195
+		elif [ "$ARCHITECTURE" == "x86_64" ]; then
196
+			juju-log "install-wxs-catalog-fixpack: no ibm_wxs_catalog_fixpack packages to install"
197
+			status-set active "IBM WXS Catalog: IBM WXS Catalog is Ready"
198
+			return 0
199
+		fi
200
+		
201
+	fi
202
+	if [ -f ${cfg_wxs_fixpack_pkg_name} ]; then
203
+		if charms.reactive is_state 'wxsgrid.available'
204
+		then
205
+			juju-log "install-wxs-catalog-fixpack: Relation is added with other servervices. Remove relations"
206
+			status-set blocked "IBM WXS Catalog: Relation with other charm is available. Remove relations."
207
+			exit 0
208
+		fi
209
+		juju-log "install-wxs-catalog-fixpack: extracting WXS fixpack packages"
210
+		ARCHIVE_DIR=`dirname $cfg_wxs_fixpack_pkg_name`
211
+		juju-log "install-wxs-catalog-fixpack: extracting the ibm_wxs_fixpack_installer resource"
212
+		status-set maintenance "IBM WXS Catalog: extracting the ibm_wxs_fixpack_installer resources"
213
+
214
+		if [ ! -d $ARCHIVE_DIR/../WXS_FP ]; then
215
+			mkdir $ARCHIVE_DIR/../WXS_FP
216
+		fi
217
+		if ! unzip ${cfg_wxs_fixpack_pkg_name} -d ${ARCHIVE_DIR}/../WXS_FP
218
+		then
219
+			juju-log "install-wxs-catalog-fixpack: Unable to extract the WXS fixpack package content. Verify whether the package is corrupt."
220
+			status-set blocked "IBM WXS Catalog: IBM WXS fixpack package is corrupt"
221
+			rm -rf $ARCHIVE_DIR/../WXS_FP
222
+			exit 0
223
+		else
224
+			juju-log "install-wxs-catalog-fixpack: Extracted WXS fixpack package"
225
+			status-set maintenance "IBM WXS Catalog: Extracted wxs fixpack package"
226
+		fi
227
+	fi
228
+
229
+	#Stop wxs catalog server
230
+	if [ -d $WXS_INSTALL_PATH ]; then
231
+		juju-log "install-wxs-catalog-fixpack: calling stop_wxs_catalog function"
232
+		if charms.reactive is_state 'ibm-wxs-catalog-server.started'; then
233
+			set +e
234
+			stop_wxs_catalog
235
+			set -e
236
+			if [ $? -eq 1 ]; then
237
+				juju-log "install-wxs-catalog-fixpack: Can not proceed for fixpack Installation, as server is running"
238
+				status-set blocked "IBM WXS Catalog : Can not proceed for fixpack Installation, catalog server is running.Stop Catalog server"
239
+				exit 0
240
+			fi
241
+		fi
242
+	fi
243
+	#Install WXS fixpack package
244
+	juju-log "install-wxs-catalog-fixpack: WXS Fix Pack Installation started"
245
+	status-set maintenance "IBM WXS Catalog: WXS Fix Pack Installation started"
246
+	if [ "$ARCHITECTURE" == "x86_64" ];then
247
+		if ! $IM_INSTALL_PATH/eclipse/tools/imcl install com.ibm.websphere.WXS.v86 -acceptLicense -installationDirectory $WXS_INSTALL_PATH -repositories ${CHARM_DIR}/../resources/WXS_FP/ 
248
+		then
249
+			juju-log "install-wxs-catalog-fixpack: Error while upgrading WXS Fix Pack"
250
+			status-set blocked "IBM WXS Catalog: Error while upgrading WXS Fix Pack"
251
+			exit 1
252
+		else
253
+			juju-log "install-wxs-catalog-fixpack: WXS Fix Pack is installed successfully"
254
+			status-set active "IBM WXS Catalog: WXS Fix Pack is installed successfully"
255
+			set_state 'ibm-wxs-catalog.updated'
256
+		fi
257
+	elif [ "$ARCHITECTURE" == "ppc64le" ]; then
258
+		if [ -d ${CHARM_DIR}/../resources/WXS_FP -a -d ${CHARM_DIR}/../resources/WXS_BASE/WXS_8600 ]; then
259
+				if ! $IM_INSTALL_PATH/eclipse/tools/imcl install com.ibm.websphere.WXS.v86 -acceptLicense -installationDirectory $WXS_INSTALL_PATH -repositories ${CHARM_DIR}/../resources/WXS_FP/,${CHARM_DIR}/../resources/WXS_BASE/WXS_8600
260
+				then
261
+					juju-log "install-wxs-catalog-fixpack: Error while Installing WXS Pack"
262
+					status-set blocked "IBM WXS Catalog: Error while Installing WXS Pack"
263
+					exit 1
264
+				else
265
+					juju-log "install-wxs-catalog-fixpack: WXS Fix Pack is installed successfully"
266
+					status-set active "IBM WXS Catalog: WXS installed successfully!"
267
+					set_state 'ibm-wxs-catalog.installed'
268
+					set_state 'ibm-wxs-catalog.updated'
269
+				fi
270
+		else
271
+				juju-log "install-wxs-catalog-fixpack: WXS needs Both Base and Fix Packages to be installed on PPC64LE"
272
+				status-set blocked "IBM WXS Catalog: WXS needs Both Base and Fix Packages to be installed on PPC64LE"
273
+				exit 0
274
+		fi
275
+	fi
276
+}
277
+
278
+
279
+@hook 'upgrade-charm'
280
+function check_fixpack(){
281
+	# The upgrade-charm hook will fire when a new resource is pushed for this
282
+	# charm. This is a good time to determine if we need to deal with a new
283
+	# fixpack.
284
+	if ! charms.reactive is_state 'ibm-wxs-catalog.updated'; then
285
+		# If there is no prior fixpack installed (because ibm-wxs-catalog.updated is not
286
+		# set), do nothing since install_wxs_catalog_fixpack will handle that case.
287
+		juju-log "check_fixpack: no fixpack has been installed; nothing to upgrade."
288
+		return 0
289
+	else
290
+		# If we have a fixpack packges already (because ibm-wxs-catalog.updated is set),
291
+		# we should fetch the latest fixpack packages and determine if it is new.
292
+		#  - If it is new, set our states so install_wxs_catalog_fixpack is called again
293
+		#  - If it is not new, do nothing
294
+		juju-log "check_fixpack: scanning for new fixpacks to install"
295
+		WXS_FP_DIR="$CHARM_DIR/../resources/ibm_wxs_fixpack_installer"
296
+	       
297
+		CUR_FP="$WXS_FP_DIR/ibm_wxs_fixpack_installer.zip"
298
+	       
299
+		if [ -f $CUR_FP ]; then
300
+			CUR_FP_MD5=`md5sum "$CUR_FP" | awk '{print $1}'`
301
+		fi
302
+
303
+		NEW_FP=`resource-get 'ibm_wxs_fixpack_installer' || echo unavailable`
304
+
305
+		if [ "$NEW_FP" = "unavailable" ]; then
306
+			juju-log "check_fixpack: no fixpack to install"
307
+			return 0
308
+		elif [ -f $NEW_FP ]; then
309
+			NEW_FP_MD5=`md5sum "$NEW_FP" | awk '{print $1}'`
310
+		fi
311
+
312
+		if [ "$CUR_FP_MD5" != "$NEW_FP_MD5" ]; then
313
+			juju-log "check_fixpack: new fixpack detected ($CUR_FP with $CUR_FP_MD5 versus $NEW_FP with $NEW_FP_MD5)"
314
+			rm -rf $CHARM_DIR/../resources/WXS_FP
315
+			remove_state 'ibm-wxs-catalog.updated'
316
+		else
317
+			juju-log "check_fixpack: no new fixpack to install"
318
+		fi
319
+	fi
320
+}
321
+
322
+@when_any 'ibm-wxs-catalog.installed' 'ibm-wxs-catalog.updated'
323
+@when_not 'ibm-wxs-catalog-server.started'
324
+function start_ibm_wxs_catalog() {
325
+	#Start wxs server
326
+	juju-log "start_ibm_wxs_catalog: calling start_wxs_catalog function"
327
+	set +e
328
+	start_wxs_catalog
329
+	set -e
330
+	if [ $? -eq 1 ]; then
331
+		juju-log "start_ibm_wxs_catalog: Could not start Catalog servr"
332
+	fi
333
+}
334
+
335
+@when 'ibm-wxs-catalog-server.started'
336
+@when 'wxsgrid.available'
337
+function export_hostname_port(){
338
+	juju-log "export_hostname_port: Inside export_hostname_port"
339
+	juju-log "export_hostname_port: IPAddress: $private_address"
340
+	juju-log "export_hostname_port: Port number: $wxs_catalog_port"
341
+	private_address=`unit-get private-address`
342
+	wxs_catalog_port=2809
343
+	services=$(relation_call --state=wxsgrid.available services) || true
344
+	for service in $services; do
345
+		juju-log "export_hostname_port: $service"
346
+		relation_call --state=wxsgrid.available set_wxs_catalog_details $service $private_address $wxs_catalog_port || true
347
+		juju-log "export_hostname_port: Exported IPAddress and Port number for service: $service"
348
+	done
349
+}
350
+
351
+@when_not 'wxsgrid.available'
352
+function remove_relation(){
353
+	juju-log "remove_relation : Removing relation from Catalog"
354
+	for service in $services; do
355
+		juju-log "remove_relation: Calling dismiss for $service"
356
+		relation_call --state=wxsgrid.departed dismiss $service || true
357
+	done
358
+	juju-log "remove_relation: Removed relation from other charms"
359
+}
360
+
361
+reactive_handler_main
Back to file index

reactive/leadership.py

 1
--- 
 2
+++ reactive/leadership.py
 3
@@ -0,0 +1,68 @@
 4
+# Copyright 2015-2016 Canonical Ltd.
 5
+#
 6
+# This file is part of the Leadership Layer for Juju.
 7
+#
 8
+# This program is free software: you can redistribute it and/or modify
 9
+# it under the terms of the GNU General Public License version 3, as
10
+# published by the Free Software Foundation.
11
+#
12
+# This program is distributed in the hope that it will be useful, but
13
+# WITHOUT ANY WARRANTY; without even the implied warranties of
14
+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
+# PURPOSE.  See the GNU General Public License for more details.
16
+#
17
+# You should have received a copy of the GNU General Public License
18
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
+
20
+from charmhelpers.core import hookenv
21
+from charmhelpers.core import unitdata
22
+
23
+from charms import reactive
24
+from charms.leadership import leader_get, leader_set
25
+
26
+
27
+__all__ = ['leader_get', 'leader_set']  # Backwards compatibility
28
+
29
+
30
+def initialize_leadership_state():
31
+    '''Initialize leadership.* states from the hook environment.
32
+
33
+    Invoked by hookenv.atstart() so states are available in
34
+    @hook decorated handlers.
35
+    '''
36
+    is_leader = hookenv.is_leader()
37
+    if is_leader:
38
+        hookenv.log('Initializing Leadership Layer (is leader)')
39
+    else:
40
+        hookenv.log('Initializing Leadership Layer (is follower)')
41
+
42
+    reactive.helpers.toggle_state('leadership.is_leader', is_leader)
43
+
44
+    previous = unitdata.kv().getrange('leadership.settings.', strip=True)
45
+    current = hookenv.leader_get()
46
+
47
+    # Handle deletions.
48
+    for key in set(previous.keys()) - set(current.keys()):
49
+        current[key] = None
50
+
51
+    any_changed = False
52
+    for key, value in current.items():
53
+        reactive.helpers.toggle_state('leadership.changed.{}'.format(key),
54
+                                      value != previous.get(key))
55
+        if value != previous.get(key):
56
+            any_changed = True
57
+        reactive.helpers.toggle_state('leadership.set.{}'.format(key),
58
+                                      value is not None)
59
+    reactive.helpers.toggle_state('leadership.changed', any_changed)
60
+
61
+    unitdata.kv().update(current, prefix='leadership.settings.')
62
+
63
+
64
+# Per https://github.com/juju-solutions/charms.reactive/issues/33,
65
+# this module may be imported multiple times so ensure the
66
+# initialization hook is only registered once. I have to piggy back
67
+# onto the namespace of a module imported before reactive discovery
68
+# to do this.
69
+if not hasattr(reactive, '_leadership_registered'):
70
+    hookenv.atstart(initialize_leadership_state)
71
+    reactive._leadership_registered = True
Back to file index

requirements.txt

1
--- 
2
+++ requirements.txt
3
@@ -0,0 +1,2 @@
4
+flake8
5
+pytest
Back to file index

revision

1
--- 
2
+++ revision
3
@@ -0,0 +1 @@
4
+0
Back to file index

tests/01-deploy.py

 1
--- 
 2
+++ tests/01-deploy.py
 3
@@ -0,0 +1,59 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+import unittest
 7
+import amulet
 8
+import re
 9
+
10
+class TestDeploy(unittest.TestCase):
11
+    """ Create a class for testing the charm in the unit test framework. """
12
+    @classmethod
13
+    def setUpClass(self):
14
+        """
15
+        Trivial deployment test for IBM WXS Catalog Server.
16
+
17
+        This charm cannot do anything useful by itself, it
18
+        will deploy WXS Catalog and allow the
19
+        /opt/ibm/WXS files to be shared. So integration testing
20
+        is done in the bundle.
21
+        """
22
+
23
+        self.d = amulet.Deployment(series='trusty')
24
+        self.d.add('ibm-wxs-catalog',
25
+                   'cs:~ibmcharmers/trusty/ibm-wxs-catalog-4')
26
+        try:
27
+            self.d.setup(timeout=10000)
28
+            self.d.sentry.wait(timeout=20000)
29
+        except amulet.helpers.TimeoutError:
30
+            amulet.raise_status(amulet.SKIP,
31
+                                msg="Environment wasn't stood up in time")
32
+        except:
33
+            raise
34
+
35
+    def test_deploy_with_placeholder_resource(self):
36
+        # The status message when using placeholder resources will include the
37
+        # string "ibm_lsf_installer resource".
38
+        # If we see that, the test is successful.
39
+        sentry_re = re.compile('ibm_wxs_base_installer resource')
40
+        self.d.sentry.wait_for_messages({"ibm-wxs-catalog":
41
+                                        sentry_re})
42
+
43
+    def test_unit_deployed(self):
44
+        # verify unit
45
+        self.assertTrue(self.d.deployed)
46
+        unit_wxscatalog_0 = self.d.sentry['ibm-wxs-catalog'][0]
47
+        state_wxscatalog = unit_wxscatalog_0.info['agent-state']
48
+        print('IBM WXS Catalog Server is %s' % state_wxscatalog)
49
+        wxs_catalog_ip = unit_wxscatalog_0.info['public-address']
50
+        print('IBM WXS Catalog Server IP is %s' % wxs_catalog_ip)
51
+        cmd = "cd /opt/ibm/WXS;pwd"
52
+        output, code = unit_wxscatalog_0.run(cmd)
53
+        if code != 0:
54
+            message = 'IBM WXS Catalog Server is not installed correctly \
55
+                      as WXS installation path does not exist'
56
+            amulet.raise_status(amulet.FAIL, msg=message)
57
+        print('IBM WXS Catalog is installed successfully at the \
58
+              following location :%s' % output)
59
+
60
+
61
+if __name__ == '__main__':
62
+    unittest.main()
Back to file index

tests/tests.yaml

1
--- 
2
+++ tests/tests.yaml
3
@@ -0,0 +1,4 @@
4
+packages:
5
+  - amulet
6
+  - python3
7
+  - unzip
Back to file index

tox.ini

 1
--- 
 2
+++ tox.ini
 3
@@ -0,0 +1,12 @@
 4
+[tox]
 5
+skipsdist=True
 6
+envlist = py34, py35
 7
+skip_missing_interpreters = True
 8
+
 9
+[testenv]
10
+commands = py.test -v
11
+deps =
12
+    -r{toxinidir}/requirements.txt
13
+
14
+[flake8]
15
+exclude=docs