Commit 2c343a23 authored by Xavier Thompson's avatar Xavier Thompson

html5as: Add demo for local promise egg

parent acc99f4c
......@@ -21,7 +21,7 @@ md5sum = 9e486efe4ab1aba8cb72b04f6c6da8ad
[instance_html5as]
_update_hash_filename_ = instance_html5as.cfg.in
md5sum = 283440057c659bde2ae7fcc2c4c5b781
md5sum = 2153820e7dac9fc9f7369304f0cec95f
[template_nginx_conf]
_update_hash_filename_ = templates/nginx_conf.in
......
......@@ -14,6 +14,7 @@ parts =
launcher
nginx-graceful
port-listening-promise
port-listening-mypromise
logrotate-entry-nginx
publish-connection-information
......@@ -190,6 +191,18 @@ name = nginx-port-listening.py
config-host = ${html5as:ip}
config-port = ${html5as:port}
# Port Listening checking promise using mypromise egg
[port-listening-mypromise]
recipe = slapos.cookbook:promise.plugin
eggs = slapos.mypromise.html5as
mode = 600
content = from promise import RunPromise
output = ${directory:plugins}/nginx-port-listening-mypromise.py
config-host = ${html5as:ip}
config-port = ${html5as:port}
# Use a port different from the default one in order to be able to
# use it in a SlapOS webrunner or a Theia SlapOS Runner
[monitor-instance-parameter]
......
from zope.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise
import socket
ADDRESS_USAGE = (
"Address must be specified in 1 of the following 3 forms:"
" (host, port), path or abstract")
@implementer(interface.IPromise)
class RunPromise(GenericPromise):
def __init__(self, config):
super(RunPromise, self).__init__(config)
self.setPeriodicity(minute=2)
self.result_count = int(self.getConfig('result-count', 3))
self.failure_amount = int(self.getConfig('failure-amount', 3))
def sense(self):
"""
Check the state of a socket.
"""
host = self.getConfig('host')
port = self.getConfig('port')
path = self.getConfig('pathname')
abstract = self.getConfig('abstract')
if host:
if path or abstract or not port:
self.logger.error(ADDRESS_USAGE)
return
# type of port must be int or str, unicode is not accepted.
family, _, _, _, addr = socket.getaddrinfo(host, int(port))[0]
else:
if bool(path) == bool(abstract):
self.logger.error(ADDRESS_USAGE)
return
family = socket.AF_UNIX
addr = path or '\0' + abstract
s = socket.socket(family, socket.SOCK_STREAM)
try:
s.connect(addr)
except socket.error as e:
self.logger.error('%s: %s', type(e).__name__, e)
else:
self.logger.info("socket connection OK %r", addr)
finally:
s.close()
def anomaly(self):
"""
By default, there is an anomaly if last 3 senses were bad.
"""
return self._anomaly(result_count=self.result_count, failure_amount=self.failure_amount)
##############################################################################
#
# Copyright (c) 2019 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from setuptools import setup, find_packages
version = '0.0.1.dev0'
name = 'slapos.mypromise.html5as'
long_description = 'A local promise for html5as'
setup(
name=name,
version=version,
description="Custom promise for SlapOS' HTML5AS",
long_description=long_description,
long_description_content_type='text/markdown',
maintainer="Nexedi",
maintainer_email="info@nexedi.com",
url="https://lab.nexedi.com/nexedi/slapos",
packages=find_packages(),
install_requires=[
'slapos.core',
],
zip_safe=True,
test_suite='test',
)
......@@ -21,6 +21,8 @@ parts =
# Call creation of instance.cfg file that will be called for deployment of
# instance
template-cfg
# Install mypromise egg
mypromise
# Download instance.cfg.in (buildout profile used to deployment of instance),
# replace all {{ foo_bar }} parameters by real values
......@@ -75,3 +77,27 @@ mode = 0644
[template_instance_replicate]
<= download-base
# Download and install the local promise egg
[mypromise-directory]
recipe = slapos.cookbook:mkdirectory
path = ${buildout:directory}/parts/mypromise
[download-promise-base]
<= download-base
url = ${:_profile_base_location_}/mypromise/${:_buildout_section_name_}
destination = ${mypromise-directory:path}/${:_buildout_section_name_}
[promise.py]
<= download-promise-base
[setup.py]
<= download-promise-base
[mypromise]
recipe = zc.recipe.egg:develop
egg = slapos.mypromise.html5as
setup = ${mypromise-directory:path}
depends =
${setup.py:destination}
${promise.py:destination}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment