diff options
author | Jack Lucas <jflucas@research.att.com> | 2019-03-22 18:31:55 -0400 |
---|---|---|
committer | Jack Lucas <jflucas@research.att.com> | 2019-03-22 18:46:13 -0400 |
commit | 205fc2e449f9bcc2f447c58d2bd15e9b563237d3 (patch) | |
tree | 97eabcf3e5252130b9626d29643084961c1602ea | |
parent | 4c67277a504a8c2c200e6fe63c7218759620a1ec (diff) |
Fix support for local type file storage
Also move to script-based readiness check so that the import resolver
rule updated needed for local type file storage takes effect before
clients try to use CM, and to verify that all CM services are really up.
Issue-ID: DCAEGEN2-989
Change-Id: I9732fa0ff38affa320b6a872b74c16f87b73eb67
Signed-off-by: Jack Lucas <jflucas@research.att.com>
-rw-r--r-- | cm-container/Dockerfile-template | 5 | ||||
-rw-r--r-- | cm-container/scripts/cloudify-ready.sh | 62 | ||||
-rwxr-xr-x | cm-container/scripts/dcae-cleanup.sh (renamed from cm-container/dcae-cleanup.sh) | 0 | ||||
-rwxr-xr-x | cm-container/scripts/get-type-files.sh (renamed from cm-container/get-type-files.sh) | 13 | ||||
-rw-r--r-- | cm-container/scripts/readiness-check.sh | 40 | ||||
-rwxr-xr-x | cm-container/scripts/set-resolver-rules.sh | 39 | ||||
-rwxr-xr-x | cm-container/scripts/setup-secret.sh (renamed from cm-container/setup-secret.sh) | 0 | ||||
-rwxr-xr-x | cm-container/scripts/start-persistent.sh (renamed from cm-container/start-persistent.sh) | 0 | ||||
-rw-r--r-- | cm-container/scripts/update_resolver.py | 56 |
9 files changed, 210 insertions, 5 deletions
diff --git a/cm-container/Dockerfile-template b/cm-container/Dockerfile-template index 9462ff5..8524ee8 100644 --- a/cm-container/Dockerfile-template +++ b/cm-container/Dockerfile-template @@ -1,7 +1,7 @@ # ============LICENSE_START======================================================= # org.onap.dcae # ================================================================================ -# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ ENV CCSDK_REPO {{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releas # Store type files locally RUN mkdir scripts -COPY get-type-files.sh dcae-cleanup.sh start-persistent.sh setup-secret.sh scripts/ +COPY scripts/* scripts/ # Load our type files and the Cloudify 3.4 type files # Setup rc.local to set up k8s credentials for CM RUN scripts/get-type-files.sh ${TYPE_REPO} ${CCSDK_REPO}\ @@ -34,6 +34,7 @@ RUN scripts/get-type-files.sh ${TYPE_REPO} ${CCSDK_REPO}\ && chown -R cfyuser:cfyuser /opt/manager/resources/spec/cloudify/3.4\ && chmod +x scripts/*.sh\ && echo "/scripts/setup-secret.sh" >> /etc/rc.d/rc.local\ + && echo "/scripts/set-resolver-rules.sh" >> /etc/rc.d/rc.local\ && chmod +x /etc/rc.d/rc.local # Create mount point for CM config file RUN mkdir -p /opt/onap && chown cfyuser:cfyuser /opt/onap diff --git a/cm-container/scripts/cloudify-ready.sh b/cm-container/scripts/cloudify-ready.sh new file mode 100644 index 0000000..60b48e6 --- /dev/null +++ b/cm-container/scripts/cloudify-ready.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# ============LICENSE_START======================================================= +# org.onap.dcae +# ================================================================================ +# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +# +# Checking Cloudify Manager readiness by looking +# for non-running services +# Relying on the output format of the "cfy status" command. +# A successful execution of the command outputs: +# +# cfy status +# Retrieving manager services status... [ip=localhost] +# +# Services: +# +--------------------------------+---------+ +# | service | status | +# +--------------------------------+---------+ +# | InfluxDB | running | +# | Logstash | running | +# | AMQP InfluxDB | running | +# | RabbitMQ | running | +# | Webserver | running | +# | Management Worker | running | +# | PostgreSQL | running | +# | Cloudify Console | running | +# | Manager Rest-Service | running | +# | Riemann | running | +# +--------------------------------+---------+ +# +# When an individual service is not running, it will have a status other than "running". +# If the Cloudify API cannot be reached, the "Services:" line will not appear. + +STAT=$(cfy status) +if (echo "${STAT}" | grep "^Services:$") +then + echo "Got a status response" + if !(echo "${STAT}" | egrep '^\| [[:alnum:]]+'| grep -iv '| running ') + then + echo "All services running" + exit 0 + else + echo "Some service(s) not running" + fi +else + echo "Did not get a status response" +fi +echo "${STAT}" +exit 1 diff --git a/cm-container/dcae-cleanup.sh b/cm-container/scripts/dcae-cleanup.sh index a9779be..a9779be 100755 --- a/cm-container/dcae-cleanup.sh +++ b/cm-container/scripts/dcae-cleanup.sh diff --git a/cm-container/get-type-files.sh b/cm-container/scripts/get-type-files.sh index e59b3b1..e6a346f 100755 --- a/cm-container/get-type-files.sh +++ b/cm-container/scripts/get-type-files.sh @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.dcae # ================================================================================ -# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ # set -x DEST=/opt/manager/resources/onapspec +EXTRA_RULES=/opt/manager/extra-resolver-rules DCAETYPEFILES=\ "\ @@ -60,11 +61,17 @@ done chown cfyuser:cfyuser ${DEST} # Add our local type file store to CM import resolver configuration -TYPE_RULE0="{$1: file://${DEST}}" -TYPE_RULE1="{$2: file://${DEST}}" +TYPE_RULE0="{\"$1\": \"file://${DEST}\"}" +TYPE_RULE1="{\"$2\": \"file://${DEST}\"}" # This sed re is 'brittle' but we can be sure the config.yaml file # won't change as long as we do not change the source Docker image for CM sed -i -e "s# rules:# rules:\n - ${TYPE_RULE0}#" /etc/cloudify/config.yaml sed -i -e "s# rules:# rules:\n - ${TYPE_RULE1}#" /etc/cloudify/config.yaml chown cfyuser:cfyuser /etc/cloudify/config.yaml + +# Changing /etc/cloudify/config.yaml is no longer sufficient +# Need to provide the additional rules in a file that can be +# used at deployment time to update the resolver rules +echo "- ${TYPE_RULE0}" > ${EXTRA_RULES} +echo "- ${TYPE_RULE1}" >> ${EXTRA_RULES}
\ No newline at end of file diff --git a/cm-container/scripts/readiness-check.sh b/cm-container/scripts/readiness-check.sh new file mode 100644 index 0000000..a7e92ab --- /dev/null +++ b/cm-container/scripts/readiness-check.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# ============LICENSE_START======================================================= +# org.onap.dcae +# ================================================================================ +# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +# +# Check whether Cloudify Manager is ready to take traffic +# Two conditions must be met: +# -- The import resolver rules must have been updated. +# This is indicated by the presence of the file named +# /opt/manager/extra-resolver-rules-loaded. +# -- All Cloudify Manager services must be running, as +# indicated by the output of the cfy status command. + +RULES_LOADED=/opt/manager/extra-resolver-rules-loaded + +set -x + +if [[ -f $RULES_LOADED ]] +then + # Check for all services running + if /scripts/cloudify-ready.sh + then + exit 0 + fi +fi +exit 1
\ No newline at end of file diff --git a/cm-container/scripts/set-resolver-rules.sh b/cm-container/scripts/set-resolver-rules.sh new file mode 100755 index 0000000..e695231 --- /dev/null +++ b/cm-container/scripts/set-resolver-rules.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# ============LICENSE_START======================================================= +# org.onap.dcae +# ================================================================================ +# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= + +set -ex +EXTRA_RULES=/opt/manager/extra-resolver-rules +PY=/opt/manager/env/bin/python +# Wait for Cloudify Manager to come up +while ! /scripts/cloudify-ready.sh +do + echo "Waiting for CM to come up" + sleep 15 +done + +if [[ -s ${EXTRA_RULES} && -r ${EXTRA_RULES} ]] +then + # Capture current resolver rules and append to new rules + ${PY} /scripts/update_resolver.py --dry-run | egrep "^-" >> ${EXTRA_RULES} + + # Update the resolver rules + ${PY} /scripts/update_resolver.py ${EXTRA_RULES} + systemctl restart cloudify-restservice.service + mv ${EXTRA_RULES} ${EXTRA_RULES}-loaded +fi
\ No newline at end of file diff --git a/cm-container/setup-secret.sh b/cm-container/scripts/setup-secret.sh index 848ed28..848ed28 100755 --- a/cm-container/setup-secret.sh +++ b/cm-container/scripts/setup-secret.sh diff --git a/cm-container/start-persistent.sh b/cm-container/scripts/start-persistent.sh index bf55da0..bf55da0 100755 --- a/cm-container/start-persistent.sh +++ b/cm-container/scripts/start-persistent.sh diff --git a/cm-container/scripts/update_resolver.py b/cm-container/scripts/update_resolver.py new file mode 100644 index 0000000..e5c9d46 --- /dev/null +++ b/cm-container/scripts/update_resolver.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +#============LICENSE_START========================================================== +# org.onap.dcae +# ================================================================================== +# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. +# ================================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END=========================================================== +# +import sys +import yaml +from sqlalchemy.orm.attributes import flag_modified +from manager_rest.flask_utils import setup_flask_app +from manager_rest.constants import PROVIDER_CONTEXT_ID +from manager_rest.storage import get_storage_manager, models + + +def main(dry_run, rules_file): + + with setup_flask_app().app_context(): + sm = get_storage_manager() + ctx = sm.get(models.ProviderContext, PROVIDER_CONTEXT_ID) + print 'Resolver rules before update:' + print yaml.safe_dump(ctx.context['cloudify']['import_resolver']['parameters']['rules']) + + if dry_run: + return + + with open(rules_file, 'r') as rules: + new_rules = yaml.load(rules) + ctx.context['cloudify']['import_resolver']['parameters']['rules'] = new_rules + print '\nResolver rules to update:' + print yaml.safe_dump(new_rules) + flag_modified(ctx, 'context') + sm.update(ctx) + print '\nProvide Context Saved' + print '\nResolver rules after update:' + print yaml.safe_dump(ctx.context['cloudify']['import_resolver']['parameters']['rules']) + + +if __name__ == '__main__': + if len(sys.argv) < 2: + print 'Must provide path to yaml file containing new rules or --dry-run' + exit(1) + + main(sys.argv[1]=='--dry-run', sys.argv[1])
\ No newline at end of file |