diff --git a/centos_guest_image.inc b/centos_guest_image.inc index e22c777a..5da9dabf 100644 --- a/centos_guest_image.inc +++ b/centos_guest_image.inc @@ -9,8 +9,5 @@ # guest-client guest-client -# guest-scale-agent -guest-scale-agent - # host-guest-comm guest-host-comm diff --git a/centos_guest_image_rt.inc b/centos_guest_image_rt.inc index 21cb7cde..3260b089 100644 --- a/centos_guest_image_rt.inc +++ b/centos_guest_image_rt.inc @@ -9,8 +9,5 @@ # guest-client guest-client -# guest-scale-agent -guest-scale-agent - # host-guest-comm guest-host-comm diff --git a/centos_iso_image.inc b/centos_iso_image.inc index 977589b6..ed1a392e 100644 --- a/centos_iso_image.inc +++ b/centos_iso_image.inc @@ -5,9 +5,6 @@ # nova-api-proxy nova-api-proxy -# guest-scale-agent -guest-scale-helper - # host-guest-comm host-guest-comm diff --git a/devstack/lib/stx-nfv b/devstack/lib/stx-nfv index 8f38e3e3..0e90849e 100644 --- a/devstack/lib/stx-nfv +++ b/devstack/lib/stx-nfv @@ -35,11 +35,6 @@ MTCE_GUEST_DIR=$STXNFV_DIR/mtce-guest MTCE_GUEST_CONF=$STXNFV_SYSCONFDIR/mtc MTCE_GUEST_OCF_DIR=$STXNFV_OCF_ROOT/resource.d/platform -# guest-agent -GUEST_AGENT_DIR=$STXNFV_DIR/guest-agent -GUEST_SCALE_AGENT_VER="2.0" -GUEST_SCALE_AGENT_DIR=$GUEST_AGENT_DIR/guest-scale-agent-$GUEST_SCALE_AGENT_VER - # guest-comm GUEST_COMM_DIR=$STXNFV_DIR/guest-comm HOST_AGENT_COMM_VER="2.0" @@ -89,10 +84,6 @@ function cleanup_guest_server { sudo rm -rf $STXNFV_SYSCONFDIR/logrotate.d/guestServer.logrotate } -function cleanup_guest_scale_helper { - $STX_SUDO rm -rf $STX_INST_DIR/sbin/guest_scale_helper -} - function cleanup_host_agent { sudo rm -rf $STXNFV_SYSCONFDIR/init.d/host_agent sudo rm -rf $STXNFV_SYSCONFDIR/pmon.d/host_agent.conf @@ -150,10 +141,6 @@ function cleanup_nfv { if is_service_enabled host-agent; then cleanup_host_agent fi - - if is_service_enabled guest-scale-helper; then - cleanup_guest_scale_helper - fi } function cleanup_nfv_client { @@ -391,15 +378,6 @@ function install_guest_server { popd } -function install_guest_scale_helper { - pushd $GUEST_SCALE_AGENT_DIR - make EXTRALDFLAGS="-L$STX_INST_DIR"/lib64 all - - $STX_SUDO install -m 750 bin/guest_scale_helper $STX_INST_DIR/sbin/guest_scale_helper - - popd -} - function install_mtce_guest_common { pushd $MTCE_GUEST_DIR/src make EXTRALDFLAGS="-L$STX_INST_DIR"/lib64 build @@ -436,10 +414,6 @@ function install_nfv { if is_service_enabled host-agent; then install_host_agent fi - - if is_service_enabled guest-scale-helper; then - install_guest_scale_helper - fi } function install_nfv_client { diff --git a/guest-agent/PKG-INFO b/guest-agent/PKG-INFO deleted file mode 100644 index e9c7c6ea..00000000 --- a/guest-agent/PKG-INFO +++ /dev/null @@ -1,12 +0,0 @@ -Metadata-Version: 1.1 -Name: guest-scale-agent -Version: 2.0 -Summary: Titanium Cloud agent and helper app to scale VMs up/down -Home-page: -Author: Windriver -Author-email: info@windriver.com -License: Apache-2.0 - -Description: Titanium Cloud agent and helper app to scale VMs up/down - -Platform: UNKNOWN diff --git a/guest-agent/centos/build_srpm.data b/guest-agent/centos/build_srpm.data deleted file mode 100644 index 55bf2d1c..00000000 --- a/guest-agent/centos/build_srpm.data +++ /dev/null @@ -1,2 +0,0 @@ -SRC_DIR="guest-scale-agent-2.0" -TIS_PATCH_VER=6 diff --git a/guest-agent/centos/guest-scale-agent.spec b/guest-agent/centos/guest-scale-agent.spec deleted file mode 100644 index bf53dad4..00000000 --- a/guest-agent/centos/guest-scale-agent.spec +++ /dev/null @@ -1,117 +0,0 @@ -Summary: Titanium Cloud agent and helper app to scale VMs up/down -Name: guest-scale-agent -Version: 2.0 -%define patchlevel %{tis_patch_ver} -Release: %{tis_patch_ver}%{?_tis_dist} -License: Apache-2.0 -Group: base -Packager: Wind River -URL: unknown - -%define cgcs_sdk_deploy_dir /opt/deploy/cgcs_sdk -Source0: %{name}-%{version}.tar.gz - -BuildRequires: json-c-devel -BuildRequires: host-guest-comm-dev -BuildRequires: guest-host-comm-dev -BuildRequires: systemd-devel - -Requires: bash - -%description -Titanium Cloud agent and helper app to scale VMs up/down - -%package -n guest-scale-agent-dbg -Summary: Titanium Cloud agent and helper app to scale VMs up/down - Debugging files -Group: devel - -%description -n guest-scale-agent-dbg -Titanium Cloud agent and helper app to scale VMs up/down This package contains ELF -symbols and related sources for debugging purposes. - -%package -n guest-scale-agent-dev -Summary: Titanium Cloud agent and helper app to scale VMs up/down - Development files -Group: devel -Requires: guest-scale-agent = %{version}-%{release} - -%description -n guest-scale-agent-dev -Titanium Cloud agent and helper app to scale VMs up/down This package contains -symbolic links, header files, and related items necessary for software -development. - -%package -n guest-scale-helper -Summary: Titanium Cloud agent and helper app to scale VMs up/down -Group: base -Requires: rtld(GNU_HASH) - -%description -n guest-scale-helper -Titanium Cloud agent and helper app to scale VMs up/down - -%package -n %{name}-cgts-sdk -Summary: SDK files for Titanium Cloud agent and helper app to scale VMs up/down -Group: devel - -%description -n %{name}-cgts-sdk -SDK files for Titanium Cloud agent and helper app to scale VMs up/down -%prep -%setup - - -%build -VER=%{version} -MAJOR=`echo $VER | awk -F . '{print $1}'` -MINOR=`echo $VER | awk -F . '{print $2}'` -PATCH=%{patchlevel} -make all VER=${VER} MAJOR=${MAJOR} MINOR=${MINOR} PATCH=${PATCH} - -%install -make install \ - DESTDIR=%{buildroot} \ - SYSCONFDIR=%{buildroot}%{_sysconfdir} \ - VERSION=%{version} PATCH=%{tis_patch_ver}\ - UNITDIR=%{buildroot}%{_unitdir} \ - SDK_DEPLOY_DIR=%{buildroot}%{cgcs_sdk_deploy_dir} - -%post -%systemd_post offline-cpus.service -%systemd_post guest-scale-agent.service -/usr/bin/systemctl enable offline-cpus.service >/dev/null 2>&1 -/usr/bin/systemctl enable guest-scale-agent.service >/dev/null 2>&1 - -%preun -%systemd_preun offline-cpus.service -%systemd_preun guest-scale-agent.service - -%postun -%systemd_postun guest-scale-agent.service -%systemd_postun offline-cpus.service - -%files -%defattr(-,root,root,-) - -/usr/sbin/guest_scale_agent -/usr/sbin/offline_cpus -/usr/sbin/app_scale_helper -/etc/init.d/offline_cpus -%{_unitdir}/offline-cpus.service -%{_unitdir}/guest-scale-agent.service - -%files -n guest-scale-agent-dbg -%defattr(-,root,root,-) - -/usr/src/debug/* -/usr/sbin/.debug/guest_scale_agent - -%files -n guest-scale-agent-dev -%defattr(-,root,root,-) - -/usr/sbin/.debug/guest_scale_agent - -%files -n guest-scale-helper -%defattr(-,root,root,-) - -/usr/sbin/guest_scale_helper - -%files -n %{name}-cgts-sdk -%{cgcs_sdk_deploy_dir}/wrs-guest-scale-%{version}.%{patchlevel}.tgz - diff --git a/guest-agent/guest-scale-agent-2.0/LICENSE b/guest-agent/guest-scale-agent-2.0/LICENSE deleted file mode 100644 index d6456956..00000000 --- a/guest-agent/guest-scale-agent-2.0/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/guest-agent/guest-scale-agent-2.0/Makefile b/guest-agent/guest-scale-agent-2.0/Makefile deleted file mode 100644 index fbf93ffd..00000000 --- a/guest-agent/guest-scale-agent-2.0/Makefile +++ /dev/null @@ -1,142 +0,0 @@ -# -# BSD LICENSE -# -# Copyright(c) 2013-2016, Wind River Systems, Inc. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Wind River Systems nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# Note: if you change either Makefile or Makefile.sdk you need to manually -# do a "make clean" and then "make". - -EXECS = guest_scale_helper guest_scale_agent - -DESTDIR ?= / -SYSCONFDIR ?= $(DESTDIR)/etc -UNITDIR ?= $(DESTDIR)/usr/lib/systemd/system -SDK_DEPLOY_DIR ?= /opt/deploy/cgcs_sdk -VERSION ?= 2.0 -PATCH ?= 0 - -CFLAGS= -g -Wall -Wformat -Wformat-security -ODIR=obj -BINDIR=bin - -BINEXECS=$(addprefix $(BINDIR)/, $(EXECS)) - -GUEST_SCALE_HELPER_SRCS = guest_scale_helper.c parser.c -GUEST_SCALE_HELPER_OBJ := $(patsubst %,$(ODIR)/%,$(GUEST_SCALE_HELPER_SRCS:.c=.o)) - -GUEST_SCALE_AGENT_SRCS= guest_scale_agent.c parser.c -GUEST_SCALE_AGENT_OBJ := $(patsubst %,$(ODIR)/%,$(GUEST_SCALE_AGENT_SRCS:.c=.o)) - -OBJS = $(GUEST_SCALE_OBJ) $(GUEST_SCALE_AGENT_OBJ) -DEPS = $(OBJS:.o=.d) sdk/sdk.d --include $(DEPS) - -EXPORT_SDK := wrs-guest-scale-$(MAJOR).$(MINOR).$(PATCH) - -# SYSROOT = $(shell for i in $(LD) ; do echo $$i; done | grep sysroot= | awk -F = '{ print $$2 }'`) -SYSROOT = $(shell echo "$(LD)" | sed -n -e 's/^.*sysroot=//p' | awk '{ print $$1 }') -LIBSERVERGROUP_VER = $(shell find $(SYSROOT) | grep libservergroup.so. | sed -n -e 's/^.*libservergroup\.so\.//p') - -print-%: - @echo $* = $($*) - -printvars: - @$(foreach V,$(sort $(.VARIABLES)), $(if $(filter-out environment% default automatic, $(origin $V)),$(warning $V=$($V) ($(value $V))))) - -.PHONY: printvars - -all: host_all -host_all: $(BINEXECS) sdk/$(EXPORT_SDK).tgz - -# The dependency tracking for the SDK tarball is rather crude. If any -# file changes they're all copied over again. This is quick, so it's -# not worth getting fancy. -sdk/$(EXPORT_SDK).tgz: printvars - @echo "Making SDK" - @mkdir -p sdk/$(EXPORT_SDK) - @mkdir -p sdk/$(EXPORT_SDK)/bin - @mkdir -p sdk/$(EXPORT_SDK)/obj - @mkdir -p sdk/$(EXPORT_SDK)/scripts - @cp scripts/* sdk/$(EXPORT_SDK)/scripts - @echo "MAJOR=$(MAJOR)" > sdk/$(EXPORT_SDK)/Makefile - @echo "MINOR=$(MINOR)" >> sdk/$(EXPORT_SDK)/Makefile - @echo "PATCH=$(PATCH)" >> sdk/$(EXPORT_SDK)/Makefile - @cat Makefile.sdk >> sdk/$(EXPORT_SDK)/Makefile - @cat docs/README.txt | sed 's/1\.0\.0/$(MAJOR).$(MINOR).$(PATCH)/' | sed 's/9.9.9/${LIBSERVERGROUP_VER}/' > sdk/$(EXPORT_SDK)/README.txt - @cp docs/TiS-Guest-Resource-Scaling.pdf sdk/$(EXPORT_SDK)/TiS-Guest-Resource-Scaling.pdf - @cp LICENSE sdk/$(EXPORT_SDK)/LICENSE - @cp $(GUEST_SCALE_AGENT_SRCS) sdk/$(EXPORT_SDK) - @cp misc.h sdk/$(EXPORT_SDK) - @cd sdk && tar czf $(EXPORT_SDK).tgz $(EXPORT_SDK) - @echo -n "sdk/$(EXPORT_SDK).tgz: Makefile.sdk docs/README.txt docs/TiS-Guest-Resource-Scaling.pdf " > sdk/sdk.d - @echo -n "scripts/init_offline_cpus scripts/offline_cpus scripts/offline-cpus.service " >> sdk/sdk.d - @echo -n "scripts/app_scale_helper " >> sdk/sdk.d - @echo -n "$(GUEST_SCALE_AGENT_SRCS) " >> sdk/sdk.d - @echo "misc.h " >> sdk/sdk.d - @echo '*' > sdk/.gitignore - - -$(ODIR)/%.o: %.c - $(CC) -c $(CFLAGS) $(CFLAGS2) -MMD -o $@ $< - -$(BINDIR)/guest_scale_agent: $(GUEST_SCALE_AGENT_OBJ) - $(CC) -o $@ $^ $(LDFLAGS) $(EXTRALDFLAGS) -lguesthostmsg -ljson-c - -$(BINDIR)/guest_scale_helper: $(GUEST_SCALE_HELPER_OBJ) - $(CC) -o $@ $^ $(LDFLAGS) $(EXTRALDFLAGS) -lhostguestmsg -ljson-c - -install: - install -d 750 -d $(DESTDIR)/usr/sbin - install -d 750 -d $(SYSCONFDIR)/init.d - - install -m 750 -d $(DESTDIR)/usr - install -m 750 -d $(DESTDIR)/usr/src - install -m 750 -d $(DESTDIR)/usr/src/debug - install -m 750 -d $(DESTDIR)/usr/src/debug/guest-scale-agent-$(VERSION) - install -d 750 -d $(DESTDIR)/usr/sbin/.debug - - install -m 750 scripts/app_scale_helper $(DESTDIR)/usr/sbin/app_scale_helper - install -m 750 scripts/offline_cpus $(DESTDIR)/usr/sbin/offline_cpus - install -m 750 bin/guest_scale_helper $(DESTDIR)/usr/sbin/guest_scale_helper - install -m 750 bin/guest_scale_agent $(DESTDIR)/usr/sbin/guest_scale_agent - install -m 750 scripts/init_offline_cpus $(SYSCONFDIR)/init.d/offline_cpus - install -m 750 bin/guest_scale_agent $(DESTDIR)/usr/sbin/.debug/guest_scale_agent - - install -d $(UNITDIR) - install -m 750 scripts/offline-cpus.service $(UNITDIR)/offline-cpus.service - install -m 750 scripts/guest-scale-agent.service $(UNITDIR)/guest-scale-agent.service - - install -d $(SDK_DEPLOY_DIR) - install -m 644 sdk/wrs-guest-scale-$(VERSION).$(PATCH).tgz $(SDK_DEPLOY_DIR)/wrs-guest-scale-$(VERSION).$(PATCH).tgz - - -# Add the host clean as a dependency to the SDK stuff -clean: host_clean -host_clean: - rm -rf sdk diff --git a/guest-agent/guest-scale-agent-2.0/Makefile.sdk b/guest-agent/guest-scale-agent-2.0/Makefile.sdk deleted file mode 100644 index 369787f9..00000000 --- a/guest-agent/guest-scale-agent-2.0/Makefile.sdk +++ /dev/null @@ -1,74 +0,0 @@ -# -# BSD LICENSE -# -# Copyright(c) 2013-2016, Wind River Systems, Inc. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Wind River Systems nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -.PHONY: all clean - -EXECS= guest_scale_agent - -CFLAGS= -g -Wall - -ODIR=obj -BINDIR=bin - -GUEST_SCALE_AGENT_SRCS= guest_scale_agent.c parser.c -GUEST_SCALE_AGENT_OBJ := $(patsubst %,$(ODIR)/%,$(GUEST_SCALE_AGENT_SRCS:.c=.o)) - -BINEXECS=$(addprefix $(BINDIR)/, $(EXECS)) - -OBJS = $(GUEST_SCALE_AGENT_OBJ) - -_DEPS = *.h -DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) -DEPS = $(OBJS:.o=.d) --include $(DEPS) - - -WRS_SERVER_GROUP_DIR ?= $(shell find ../wrs-server-group*[0-9] -maxdepth 0 -type d | sort | tail -n 1) -WRS_SERVER_GROUP_INC2 = $(WRS_SERVER_GROUP_DIR)/include -WRS_SERVER_GROUP_INC ?= $(shell if [ -d $(WRS_SERVER_GROUP_INC2) ]; then echo "$(WRS_SERVER_GROUP_INC2)"; else echo "/usr/include"; fi) -WRS_SERVER_GROUP_LIB2 = $(WRS_SERVER_GROUP_DIR)/lib -WRS_SERVER_GROUP_LIB3 = $(shell if [ -d /usr/lib64 ]; then echo "/usr/lib64"; else echo "/usr/lib"; fi) -WRS_SERVER_GROUP_LIB ?= $(shell if [ -d $(WRS_SERVER_GROUP_LIB2) ]; then echo "$(WRS_SERVER_GROUP_LIB2)"; else echo "$(WRS_SERVER_GROUP_LIB3)"; fi) - -CFLAGS += -I$(WRS_SERVER_GROUP_INC) -LDFLAGS += -L$(WRS_SERVER_GROUP_LIB) - -$(ODIR)/%.o: %.c - $(CC) -c $(CFLAGS) $(CFLAGS2) -MMD -o $@ $< - -all: $(BINEXECS) - -$(BINDIR)/guest_scale_agent: $(GUEST_SCALE_AGENT_OBJ) - $(CC) -o $@ $^ $(LDFLAGS) -lguesthostmsg -ljson-c - -clean: - rm -rf $(ODIR)/* *~ core $(BINDIR)/* diff --git a/guest-agent/guest-scale-agent-2.0/bin/.gitignore b/guest-agent/guest-scale-agent-2.0/bin/.gitignore deleted file mode 100644 index 5e7d2734..00000000 --- a/guest-agent/guest-scale-agent-2.0/bin/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/guest-agent/guest-scale-agent-2.0/docs/README.txt b/guest-agent/guest-scale-agent-2.0/docs/README.txt deleted file mode 100644 index 03c2f62c..00000000 --- a/guest-agent/guest-scale-agent-2.0/docs/README.txt +++ /dev/null @@ -1,243 +0,0 @@ -BSD LICENSE - -Copyright(c) 2013-2016, Wind River Systems, Inc. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - * Neither the name of Wind River Systems nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------ - -DESCRIPTION -=========== -Guest Server Scaling is a service to allow a guest to scale the capacity of a -single guest server up and down on demand. - -Current supported scaling operation is CPU scaling. - -The resources can be scaled up/down from the nova CLI or GUI. Scaling can also -be set up via heat to be automatically triggered based on Ceilometer statistics. -(This will not be covered in this document, see the full documentation and the -heat SDK for how to configure heat templates for scaling a single guest server.) - -This package contains an agent and a number of scripts to be included in the -guest image. These will handle the guest side of the coordinated efforts -involved in scaling up/down guest resources. - - -DEPENDENCIES -============ - NOTE that this wrs-guest-scale SDK module has both a compile-time and run-time - dependency on the wrs-server-group SDK module. - - This wrs-guest-scale SDK module requires that the wrs-server-group SDK tarball - has been previously extracted and built, and that the resulting libraries - and headers have been placed in a location that can be found by the normal build - tools, or the WRS_SERVER_GROUP_DIR environment variable has been set. - - The output of BOTH the wrs-guest-scale SDK module and the wrs-server-group SDK - module are required to be installed in a guest image for guest resource scaling. - - -REQUIREMENTS -============ - Compilation: - Linux OS, x86_64 architecture - gcc compiler - development libraries and headers for glibc - development libraries and headers for libguesthostmsg - (built by the wrs-server-group SDK package) - development libraries and headers for json-c - - VM Runtime: - Linux OS, x86_64 architecture; CONFIG_HOTPLUG_CPU=y|m - runtime libraries for glibc - runtime libraries for libguesthostmsg - "guest_agent" binary daemon - (provided by the wrs-server-group SDK package) - runtime libraries for json-c - - The code has been tested with glibc 2.15, gcc 4.6 and json-c 0.12.99 but it - should run on other versions without difficulty. - - -DELIVERABLE -=========== -The Guest Server Scaling service is delivered as source with the required -Makefiles in a compressed tarball called "wrs-guest-scale-#.#.#.tgz", such that -it can be compiled for the applicable guest linux distribution. - - -COMPILE -======= -Pre-requisite: - Ensure that the wrs-server-group SDK tarball has been previously extracted and - built, and that the resulting libraries and headers have been placed in a - location that can be found by the normal build tools, or the WRS_SERVER_GROUP_DIR - environment variable has been set. - -Extract the tarball contents: - - tar xvf wrs-guest-scale-#.#.#.tgz - -To compile: - - # Note: assumes wrs-server-group-#.#.#.tgz has already been extracted and compiled. - - cd wrs-guest-scale-#.#.# - - # If wrs-guest-scale-#.#.#.tgz and wrs-server-group-#.#.#.tgz where extracted in a common directory - make - - # Otherwise supply the path to where wrs-server-group can be found. e.g. - make WRS_SERVER_GROUP_DIR=/usr/src/wrs-server-group-#.#.# - -This will produce: - -1) An executable "bin/guest_scale_agent". This handles the basic vCPU scaling -in the guest, and calls out to a helper script if present to support -application-specific customization. It should be configured to respawn -(via /etc/inittab or some other process monitor) if it dies for any reason. -This executable must be installed into the guest (e.g. in "/usr/sbin") and configured -to run at startup as early as possible. -NOTE - The "guest_agent" executable from the wrs-server-group SDK package MUST ALSO - be installed into the guest (e.g. in "/usr/bin"), configured to run at startup - as early as possible and configured to respawn via /etc/inittab or some other - process monitor (in case it dies for any reason). - -2) A script "script/app_scale_helper". This is an optional script that is -intended to allow for app-specific customization. If present, it must be -installed in "/usr/sbin". If present, it will be called by "guest_scale_agent" -when scaling in either direction. - -3) A script "script/offline_cpus". This must be run later in the init sequence, -after guest_scale_agent has started up but before the application has started -any CPU-affined applications. A helper script "script/init_offline_cpus" has -been provided, and should be installed to "/etc/init.d/offline_cpus. The -"offline_cpus" script will offline vCPUs in the guest to match the status on -the hypervisor. This covers the case where we are booting up with some CPUs -offlined by the hypervisor. - -4) For systemd users, the files "scripts/guest-scale-agent.service" and -"scripts/offline-cpus.service" should be copied to /lib/systemd/system/. - - -Note: -The inclusion of the files into the build system and the guest image and the -configuration of the guest startup scripts is left up to the user to allow for -different build systems and init subsystems in the guest. - - -INSTALL -======= -Installing in a running VM: - - As the root user - 1) Copy "bin/guest_scale_agent" to /usr/sbin in the VM. - - 2) Copy "scripts/app_scale_helper" and "scripts/offline_cpus" to /usr/sbin in the VM. - - 3) Copy "scripts/init_offline_cpus" to "/etc/init.d/offline_cpus". (Note the name change.) - - 4) Copy "scripts/guest-scale-agent.service" and "scripts/offline-cpus.service" to - /lib/systemd/system/. - - 5) Run "systemctl enable guest-scale-agent.service", "systemctl enable offline-cpus.service", - "systemctl start guest-scale-agent.service", "systemctl start offline-cpus.service" - -The VM should now be ready to scale up and down. - - -USAGE -===== -The service is designed to be simple to use. A basic description is given -below, but more details are provided in the source and scripts. - -1) Create a new flavor (or edit an existing flavor) such that the number of -vCPUs in the flavor matches the desired maximum number of vCPUs. To specify the -minimum number of vCPUs, create an "extra spec" metadata entry for the flavor -with a key of "wrs:min_vcpus" and a value that is an integer number between one -and the max number of vCPUs. This can be done from the CLI or the GUI. (In the -GUI select the "Admin" tab, go to the "Flavor" navigation link, click on a -flavor name, select the "Extra Specs" tab, click on "Create", select -"Minimum Number of CPUs" from the pulldown, and enter the desired value.) - -2) Build BOTH the wrs-server-group SDK package and this wrs-guest-scale package, -and install the output of BOTH packages in an image. Lastly, ensure that the -CONFIG_HOTPLUG_CPU kernel config option is set in the image kernel. - -3) Boot the image. It will come up with the full set of vCPUs. - -4) To reduce the number of online vCPUs in the guest server, run -"nova scale cpu down" from the controller (or anywhere else you can run -nova commands). This will pass a message up into the guest, where it will be -handled by "guest_scale_agent". That in turn will call out to -"/usr/sbin/app_scale_helper" (if it exists) which is expected to pick a vCPU to -offline. This script can be modified/replaced as needed for application- -specific purposes. By default, it will select the highest-numbered online vCPU. -If the script isn't present or errors out, then "guest_scale_agent" will itself -select the highest-numbered online vCPU as the one to be offlined. It will then -tell the guest kernel to offline the selected vCPU, and will pass the selected -vCPU back down to the hypervisor, which will adjust vCPU affinity so that the -underlying physical CPU can be freed up for use by other VMs. At this point -displaying the information for the guest server will show it using less than the -maximum number of cpus. - -5) To increase the number of online vCPUs, run "nova scale cpu up". -Assuming the resources are available the hypervisor will allocate a physical CPU -and will associate it with the guest server. "guest_scale_agent" will set the -lowest-numbered offline vCPU to "online", and will pass the vCPU number to -"/usr/sbin/app_scale_helper" (if it exists) for the application to do any -special handling that may be required. - - -The behaviour of a scaled-down server during various nova operations is as -follows: - -live migration: server remains scaled-down -pause/unpause: server remains scaled-down -stop/start: server remains scaled-down -evacuation: server remains scaled-down -rebuild: server remains scaled-down -automatic restart on crash: server remains scaled-down -cold migration: server reverts to max vcpus -resize: server reverts to max vcpus for the new flavor - -If a snapshot is taken of a scaled-down server, a new server booting the -snapshot will start with the number of vCPUs specified by the flavor. - -CAVEATS -======= -It is possible for the scale-up operation to fail if the worker node has -already allocated all of its resources to other guests. If this happens, -the system will not do any automatic migration to try to free up resources. -Manual action will be required to free up resources. - -Any CPUs that are handling userspace DPDK/AVP packet processing should not be -offlined. It may appear to work, but may lead to packet loss. This can be -enforced by setting the wrs:min_vcpus value appropriately high. - -If hyperthreading is used, the flavor must set hw:cpu_thread_policy to -isolate and set cpu_policy to dedicated. diff --git a/guest-agent/guest-scale-agent-2.0/docs/TiS-Guest-Resource-Scaling.doc b/guest-agent/guest-scale-agent-2.0/docs/TiS-Guest-Resource-Scaling.doc deleted file mode 100644 index 5e0ad4da..00000000 Binary files a/guest-agent/guest-scale-agent-2.0/docs/TiS-Guest-Resource-Scaling.doc and /dev/null differ diff --git a/guest-agent/guest-scale-agent-2.0/docs/TiS-Guest-Resource-Scaling.pdf b/guest-agent/guest-scale-agent-2.0/docs/TiS-Guest-Resource-Scaling.pdf deleted file mode 100644 index 70092031..00000000 Binary files a/guest-agent/guest-scale-agent-2.0/docs/TiS-Guest-Resource-Scaling.pdf and /dev/null differ diff --git a/guest-agent/guest-scale-agent-2.0/guest_scale_agent.c b/guest-agent/guest-scale-agent-2.0/guest_scale_agent.c deleted file mode 100644 index 39c5e62c..00000000 --- a/guest-agent/guest-scale-agent-2.0/guest_scale_agent.c +++ /dev/null @@ -1,523 +0,0 @@ -/** -* Copyright (c) <2013-2016>, Wind River Systems, Inc. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1) Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2) Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation and/or -* other materials provided with the distribution. -* -* 3) Neither the name of Wind River Systems nor the names of its contributors may be -* used to endorse or promote products derived from this software without specific -* prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "misc.h" - -gh_info_t *info; - -/* Scaling Request/Response message is encoded in JSON format. - The message sent out to UNIX socket is a null-terminated JSON format string - without embedded newlines. - - Format: - {key:value,key:value,..., key:value} - - Key/value pairs for Scaling Request: - "version": - version of the interface - "timeout_ms": - timeout for app_scale_helper scripts - "resource": “cpu” - indicate the resource to scale. - Only cpu is currently supported. - "direction“: "up” or “down” - "online_cpu": - vcpu number to online when scale up - "online_cpus": - array of current online cpus - when request was sent. - example: [0,1,2,3,4,5] - - Key/value pairs for Scaling Response: - "version": - "resource": “cpu” - "direction“: "up” or “down” - "online_cpu": - vcpu number to online when scale up - "offline_cpu": - actual offlined vcpu number - "online_cpus": - array of current online cpus - when response was sent. - "result": "success" or "fail" - "err_msg": - error message if result is fail - -*/ - -#define CPU_SCRIPT "/usr/sbin/app_scale_helper" - -// generic function to call out to helper script -// need to add support for timeout in here in case script hangs -int call_helper_script(char *cmd, int timeout_ms) -{ - FILE *fp; - int rc; - - fp = popen(cmd, "w"); - if (fp) { - rc = pclose(fp); - if (rc == -1) { - ERR_LOG("pclose failed: %m"); - return -1; - } else { - if (WIFEXITED(rc)) { - rc = WEXITSTATUS(rc); - if (rc == 127) { - ERR_LOG("problem with shell or helper script, possibly script missing"); - return -1; - } else - return rc; - } else { - return -1; - } - } - } else { - ERR_LOG("popen failed due to fork/pipe/memory"); - return -1; - } -} - - -int online_cpu(unsigned cpu) -{ - int fd; - int rc; - char buf[100]; - char val; - snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%u/online", cpu); - fd = open(buf, O_RDWR); - if (fd < 0) { - ERR_LOG("can't open cpu online path: %m"); - return -1; - } - rc = read(fd, &val, 1); - if (rc != 1){ - ERR_LOG("can't read cpu online value: %m"); - close(fd); - return -1; - } - if (val == '1') { - ERR_LOG("cpu %d is already online", cpu); - close(fd); - return 0; - } - val = '1'; - rc = write(fd, &val, 1); - close(fd); - if (rc != 1){ - ERR_LOG("can't set cpu %d online", cpu); - return -1; - } - return 0; -} - -int offline_cpu(unsigned cpu) -{ - int fd; - int rc; - char buf[100]; - char val; - snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%u/online", cpu); - fd = open(buf, O_RDWR); - if (fd < 0) { - ERR_LOG("can't open cpu online path: %m"); - return -1; - } - rc = read(fd, &val, 1); - if (rc != 1){ - ERR_LOG("can't read cpu online value: %m"); - close(fd); - return -1; - } - if (val == '0') { - ERR_LOG("cpu %d is already offline\n", cpu); - close(fd); - return 0; - } - val = '0'; - rc = write(fd, &val, 1); - close(fd); - if (rc != 1){ - ERR_LOG("can't set cpu %d offline", cpu); - return -1; - } - return 0; -} - -// read /sys/devices/system/cpu/online and get the last cpu listed -int get_highest_online_cpu(void) -{ - int fd, rc; - char buf[256]; - char *start; - unsigned int cpu; - fd = open("/sys/devices/system/cpu/online", O_RDONLY); - if (fd < 0) { - ERR_LOG("can't fopen /sys/devices/system/cpu/online: %m"); - return -1; - } - - rc = read(fd, buf, sizeof(buf)); - close(fd); - if (rc < 2) { - ERR_LOG("error parsing /sys/devices/system/cpu/online, too few chars"); - return -1; - } - - // go to the end of the string - start = buf+rc-1; - if(*start != '\n') { - ERR_LOG("error parsing /sys/devices/system/cpu/online, not null-terminated"); - return -1; - } - - // now go backwards until we get to a separator or the beginning of the string - while ((*start != ',') && (*start != '-') && (start != buf)) - start--; - - start++; - rc = sscanf(start, "%u", &cpu); - if (rc != 1) { - ERR_LOG("error parsing /sys/devices/system/cpu/online, bad number"); - return -1; - } - - return cpu; -} - - -char *get_online_cpu_range(void) -{ - FILE *file; - int rc; - char *str = NULL; - file = fopen("/sys/devices/system/cpu/online", "r"); - if (!file) { - ERR_LOG("can't fopen /sys/devices/system/cpu/online: %m"); - return 0; - } - rc = fscanf(file, "%ms", &str); - if (rc != 1) - ERR_LOG("can't read /sys/devices/system/cpu/online: %m"); - fclose(file); - return str; -} - - -void cpu_scale_down(json_object *jobj_request, - json_object *jobj_response) -{ - char cmd[1000]; - int cpu=-1; - int rc; - - //build our command to send to the helper script - rc = snprintf(cmd, sizeof(cmd), "%s --cpu_del\n", CPU_SCRIPT); - if ((rc > sizeof(cmd)) || rc < 0) { - ERR_LOG("error generating command: %m"); - goto pick_cpu; - } - - struct json_object *jobj_timeout_ms; - int timeout_ms; - if (!json_object_object_get_ex(jobj_request, TIMEOUT_MS, &jobj_timeout_ms)) - { - ERR_LOG("failed to parse timeout_ms"); - goto failed; - } - - errno = 0; - timeout_ms = json_object_get_int(jobj_timeout_ms); - if(errno){ - ERR_LOG("Error converting timeout_ms: %s", strerror(errno)); - goto failed; - } - - // call app helper script to select cpu to offline - rc = call_helper_script(cmd, timeout_ms); - if (rc < 0) { - ERR_LOG("call to app helper script failed\n"); - goto pick_cpu; - } else if (rc == 0) { - ERR_LOG("call to app helper script return invalid cpu number 0\n"); - goto pick_cpu; - } else { - INFO_LOG("app helper script chose cpu %d to offline\n", rc); - cpu = rc; - } - -pick_cpu: - // if the app helper script doesn't exist or didn't return - // a cpu to offline, pick one ourselves - if (cpu == -1) { - cpu = get_highest_online_cpu(); - if (cpu <= 0) { - ERR_LOG("unable to find cpu to offline\n"); - goto failed; - } - } - - // try to offline selected cpu - rc = offline_cpu(cpu); - if (rc < 0) { - ERR_LOG("failed to set cpu %d offline\n", cpu); - goto failed; - } - - INFO_LOG("set cpu %d offline", cpu); - - // we have successfully offlined the cpu - json_object_object_add(jobj_response, RESULT, json_object_new_string("success")); - json_object_object_add(jobj_response, OFFLINE_CPU, json_object_new_int(cpu)); - struct online_cpus *current_online_cpus = range_to_array(get_online_cpu_range()); - - // no need to release jobj_array as its ownership is transferred to jobj_response - struct json_object *jobj_array = new_json_obj_from_array(current_online_cpus); - json_object_object_add(jobj_response, ONLINE_CPUS, jobj_array); - free(current_online_cpus); - return; - -failed: - json_object_object_add(jobj_response, RESULT, json_object_new_string("fail")); - json_object_object_add(jobj_response, ERR_MSG, json_object_new_string(errorbuf)); - return; -} - - -void cpu_scale_up(json_object *jobj_request, - json_object *jobj_response) -{ - char cmd[1000]; - struct json_object *jobj_timeout_ms; - if (!json_object_object_get_ex(jobj_request, TIMEOUT_MS, &jobj_timeout_ms)) { - ERR_LOG("failed to parse timeout_ms"); - goto failed; - } - int timeout_ms = json_object_get_int(jobj_timeout_ms); - - struct json_object *jobj_cpu; - if (!json_object_object_get_ex(jobj_request, ONLINE_CPU, &jobj_cpu)) { - ERR_LOG("failed to parse online_cpu"); - goto failed; - } - int cpu = json_object_get_int(jobj_cpu); - - //online_cpus is optional - struct json_object *jobj_online_cpus; - const char *online_cpus; - if (!json_object_object_get_ex(jobj_request, ONLINE_CPUS, &jobj_online_cpus)) { - ERR_LOG("failed to parse online_cpus"); - goto failed; - } - - json_object_object_get_ex(jobj_request, ONLINE_CPUS, &jobj_online_cpus); - if (!json_object_is_type(jobj_online_cpus, json_type_array)) { - ERR_LOG("failed to parse online_cpus"); - goto failed; - } - online_cpus = json_object_to_json_string_ext(jobj_online_cpus, JSON_C_TO_STRING_PLAIN); - - int rc = online_cpu(cpu); - if (rc < 0) { - printf("failed to set cpu %d online\n", cpu); - goto failed; - } - - INFO_LOG("set cpu %d online", cpu); - - // Now try to call out to the helper script - // If it fails, not the end of the world. - - rc = snprintf(cmd, sizeof(cmd), "%s --cpu_add %d %s\n", - CPU_SCRIPT, cpu, online_cpus); - - if ((rc > 0) && (rc < sizeof(cmd))) { - rc = call_helper_script(cmd, timeout_ms); - if (rc != 0) - ERR_LOG("call to app helper script failed, return code: %d\n", rc); - } else - ERR_LOG("error generating command: %m"); - - json_object_object_add(jobj_response, RESULT, json_object_new_string("success")); - json_object_object_add(jobj_response, ONLINE_CPU, json_object_new_int(cpu)); - struct online_cpus *current_online_cpus = range_to_array(get_online_cpu_range()); - - // no need to release jobj_array as its ownership is transferred to jobj_response - struct json_object *jobj_array = new_json_obj_from_array(current_online_cpus); - json_object_object_add(jobj_response, ONLINE_CPUS, jobj_array); - free(current_online_cpus); - return; - -failed: - json_object_object_add(jobj_response, RESULT, json_object_new_string("fail")); - json_object_object_add(jobj_response, ERR_MSG, json_object_new_string(errorbuf)); - return; -} - - -/* Callback message handler. This will be called by the generic guest/host - * messaging library when a valid message arrives from the host. - */ -void msg_handler(const char *source_addr, json_object *jobj_request) -{ - int rc; - - // parse version - struct json_object *jobj_version; - if (!json_object_object_get_ex(jobj_request, VERSION, &jobj_version)) { - ERR_LOG("failed to parse version"); - return; - } - int version = json_object_get_int(jobj_version); - - if (version != CUR_VERSION) { - ERR_LOG("invalid version %d, expecting %d", version, CUR_VERSION); - return; - } - - // parse msg_type - struct json_object *jobj_msg_type; - if (!json_object_object_get_ex(jobj_request, MSG_TYPE, &jobj_msg_type)) { - ERR_LOG("failed to parse msg_type"); - return; - } - const char *msg_type = json_object_get_string(jobj_msg_type); - - if (!strcmp(msg_type, MSG_TYPE_NACK)) { - struct json_object *jobj_log_msg; - if (!json_object_object_get_ex(jobj_request, LOG_MSG, &jobj_log_msg)) { - ERR_LOG("Nack: failed to parse log_msg"); - } - const char *log_msg = json_object_get_string(jobj_log_msg); - ERR_LOG("Nack received, error message from host: %s", log_msg); - return; - } else if (!strcmp(msg_type, MSG_TYPE_SCALE_REQUEST)) { - ; - } else { - ERR_LOG("unknown message type: %s", msg_type); - return; - } - - struct json_object *jobj_response = json_object_new_object(); - if (jobj_response == NULL) { - ERR_LOG("failed to allocate json object for response"); - return; - } - - struct json_object *jobj_resource; - if (!json_object_object_get_ex(jobj_request, RESOURCE, &jobj_resource)) { - ERR_LOG("failed to parse resource"); - goto done; - } - const char *resource = json_object_get_string(jobj_resource); - - struct json_object *jobj_direction; - if (!json_object_object_get_ex(jobj_request, DIRECTION, &jobj_direction)) { - ERR_LOG("failed to parse direction'"); - goto done; - } - const char *direction = json_object_get_string(jobj_direction); - - rc = -1; - if (!strcmp(resource,"cpu")) { - if (!strcmp(direction,"up")) { - cpu_scale_up(jobj_request, jobj_response); - } else if (!strcmp(direction,"down")) { - cpu_scale_down(jobj_request, jobj_response); - } - } - - json_object_object_add(jobj_response, VERSION, json_object_new_int(CUR_VERSION)); - json_object_object_add(jobj_response, RESOURCE, jobj_resource); - json_object_object_add(jobj_response, DIRECTION, jobj_direction); - - const char *response = json_object_to_json_string_ext(jobj_response, JSON_C_TO_STRING_PLAIN); - - // Send response back to the sender. - rc = gh_send_msg(info, source_addr, response); - if (rc < 0) { - ERR_LOG("gh_send_msg failed: %s\n", gh_get_error(info)); - return; - } -done: - json_object_put(jobj_response); -} - - -void wait_for_messages(int fd) -{ - int rc; - fd_set rfds, rfds_tmp; - - FD_ZERO(&rfds); - FD_SET(fd, &rfds); - - while(1) { - rfds_tmp = rfds; - rc = select(fd+1, &rfds_tmp, NULL, NULL, NULL); - if (rc > 0) { - if (gh_process_msg(info) < 0) { - ERR_LOG("problem processing messages: %s\n", - gh_get_error(info)); - } - } else if (rc < 0) { - ERR_LOG("select(): %m"); - } - } -} - - -int main() -{ - int fd = gh_init(msg_handler, SCALE_AGENT_ADDR, &info); - if (fd == -1) { - if (!info) - ERR_LOG("Unable to allocate memory for info: %m"); - else - ERR_LOG("Unable to initialize guest/host messaging: %s\n", - gh_get_error(info)); - return -1; - } - INFO_LOG("Running offline_cpus script"); - system("offline_cpus"); - wait_for_messages(fd); - - return 0; -} diff --git a/guest-agent/guest-scale-agent-2.0/guest_scale_helper.c b/guest-agent/guest-scale-agent-2.0/guest_scale_helper.c deleted file mode 100644 index cf7207b6..00000000 --- a/guest-agent/guest-scale-agent-2.0/guest_scale_helper.c +++ /dev/null @@ -1,534 +0,0 @@ -/** -* Copyright (c) <2013-2016>, Wind River Systems, Inc. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1) Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2) Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation and/or -* other materials provided with the distribution. -* -* 3) Neither the name of Wind River Systems nor the names of its contributors may be -* used to endorse or promote products derived from this software without specific -* prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - - - -/* This is intended to run as a helper function, called by nova, to pass data up - * into the guest and receive data back from the guest and return it to nova. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "misc.h" - -hg_info_t *info; - -#define SPARE_ALLOC 128 - -#define INSTANCE_NAME_SIZE 32 -#define NACK_LOG_SIZE 500 - -#define UNIX_ADDR_LEN 16 -#define DEFAULT_TIMEOUT_MS 1000 -#define TIMEOUT_OVERHEAD_MS 500 -#define MIN_SCRIPT_TIMEOUT_MS 500 -int timeout_ms = DEFAULT_TIMEOUT_MS; - -int *request_online_cpus; -int len_request_online_cpus; -int request_cpu; - -void usage() { - printf("guest_scale_helper --instance_name \n"); - printf(" --cpu_del | --cpu_add \n"); - printf(" [--timeout ]\n"); - printf("\n"); - exit(-1); -} - -void handle_cpu_scale_up(json_object *jobj_response, const char *source_instance) -{ - int rc = -1; - char log_msg[NACK_LOG_SIZE]; - - struct json_object *jobj_result; - if (!json_object_object_get_ex(jobj_response, RESULT, &jobj_result)) { - snprintf(log_msg, NACK_LOG_SIZE, "failed to parse result"); - goto failed; - } - const char *result = json_object_get_string(jobj_result); - - if (!strcmp(result, "fail")) { - struct json_object *jobj_err_msg; - const char *err_msg; - - if (!json_object_object_get_ex(jobj_response, ERR_MSG, &jobj_err_msg)) - err_msg=""; - else - err_msg = json_object_get_string(jobj_err_msg); - ERR_LOG("Error: guest helper scaling cpu up failed: %s\n", err_msg); - goto out; - } - - struct json_object *jobj_online_cpu; - if (!json_object_object_get_ex(jobj_response, ONLINE_CPU, &jobj_online_cpu)) { - snprintf(log_msg, NACK_LOG_SIZE, "failed to parse online_cpu"); - goto failed; - } - int online_cpu = json_object_get_int(jobj_online_cpu); - - struct json_object *jobj_online_cpus; - - json_object_object_get_ex(jobj_response, ONLINE_CPUS, &jobj_online_cpus); - if (!json_object_is_type(jobj_online_cpus, json_type_array)) { - snprintf(log_msg, NACK_LOG_SIZE, "failed to parse online_cpus"); - goto failed; - } - - int i, len_response; - len_response = json_object_array_length(jobj_online_cpus); - int *response_online_cpus = malloc(len_response*sizeof(int)); - - for (i=0; i< len_response; i++){ - response_online_cpus[i] = json_object_get_int(json_object_array_get_idx(jobj_online_cpus, i)); - } - - // compare request and response, assuming cpus are in the same order - if ( (len_response - len_request_online_cpus ) <=1 ) { - int req =0; - int rsp = 0; - int found_req = 0; - while (req < len_request_online_cpus){ - - if (response_online_cpus[rsp] == request_online_cpus[req]) { - req++; rsp++; - } else if (response_online_cpus[rsp] == request_cpu) { - rsp++; - found_req = 1; - // protect against infinite loop - if (rsp == len_response) - break; - } else { - ERR_LOG("Error: cpu %d online by guest but not online in nova\n", response_online_cpus[rsp]); - break; - } - } - - if ((!found_req) && (req == len_request_online_cpus)) { - if ((len_response == len_request_online_cpus) || - (response_online_cpus[len_response] != request_cpu)) { - ERR_LOG("Error: cpu %d online by nova but not online in guest\n", response_online_cpus[req]); - } - } - } - else { - ERR_LOG("Error: guest's online cpu range doesn't match nova\n"); - char buf[1024]; - print_array(buf, response_online_cpus, len_response); - ERR_LOG("guest online cpu range: %s\n", buf); - } - - // Yay, everything looks good. - free(response_online_cpus); - free(request_online_cpus); - exit(online_cpu); - rc = online_cpu; -failed: - send_nack(log_msg, source_instance); -out: - free(request_online_cpus); - exit(rc); -} - - -void handle_cpu_scale_down(json_object *jobj_response, const char *source_instance) -{ - int rc = -1; - struct json_object *jobj_result; - char log_msg[NACK_LOG_SIZE]; - - if (!json_object_object_get_ex(jobj_response, RESULT, &jobj_result)) { - snprintf(log_msg, NACK_LOG_SIZE, "failed to parse result"); - goto failed; - } - const char *result = json_object_get_string(jobj_result); - - if (!strcmp(result, "fail")) { - struct json_object *jobj_err_msg; - const char *err_msg; - if (!json_object_object_get_ex(jobj_response, ERR_MSG, &jobj_err_msg)) - err_msg=""; - else - err_msg = json_object_get_string(jobj_err_msg); - ERR_LOG("problem, guest helper scaling cpu down failed: %s\n", err_msg); - goto out; - } - - struct json_object *jobj_offline_cpu; - if (!json_object_object_get_ex(jobj_response, OFFLINE_CPU, &jobj_offline_cpu)) { - snprintf(log_msg, NACK_LOG_SIZE, "failed to parse offline_cpu"); - goto failed; - } - int offline_cpu = json_object_get_int(jobj_offline_cpu); - - struct json_object *jobj_online_cpus; - json_object_object_get_ex(jobj_response, ONLINE_CPUS, &jobj_online_cpus); - if (!json_object_is_type(jobj_online_cpus, json_type_array)) { - snprintf(log_msg, NACK_LOG_SIZE, "failed to parse online_cpus"); - goto failed; - } - - int i, len_response; - len_response = json_object_array_length(jobj_online_cpus); - int *response_online_cpus = malloc(len_response*sizeof(int)); - - for (i=0; i< len_response; i++){ - response_online_cpus[i] = json_object_get_int(json_object_array_get_idx(jobj_online_cpus, i)); - } - - if (response_online_cpus[len_response] > offline_cpu) { - ERR_LOG("Error: cpu %d is still online in guest\n", offline_cpu); - } - - // Yay, everything looks good. - free(response_online_cpus); - free(request_online_cpus); - rc = offline_cpu; - exit(rc); -failed: - send_nack(log_msg, source_instance); -out: - free(request_online_cpus); - exit(rc); -} - -// This should call exit(0) on success or exit(-1) on permanent failure(). -// Returning will continue listening. -// Theoretically this could come from any instance, need to fix that. -void msg_handler(const char *source_addr, const char *source_instance, struct json_object *jobj_response) -{ - // parse version - struct json_object *jobj_version; - char log_msg[NACK_LOG_SIZE]; - - if (!json_object_object_get_ex(jobj_response, VERSION, &jobj_version)) { - snprintf(log_msg, NACK_LOG_SIZE, "failed to parse version"); - goto failed; - } - int version = json_object_get_int(jobj_version); - - if (version != CUR_VERSION) { - snprintf(log_msg, NACK_LOG_SIZE, "invalid version %d, expecting %d", version, CUR_VERSION); - goto failed; - } - - struct json_object *jobj_resource; - if (!json_object_object_get_ex(jobj_response, RESOURCE, &jobj_resource)) { - snprintf(log_msg, NACK_LOG_SIZE, "failed to parse resource"); - goto failed; - } - const char *resource = json_object_get_string(jobj_resource); - - struct json_object *jobj_direction; - if (!json_object_object_get_ex(jobj_response, DIRECTION, &jobj_direction)) { - snprintf(log_msg, NACK_LOG_SIZE, "failed to parse direction"); - goto failed; - } - const char *direction = json_object_get_string(jobj_direction); - - if (!strcmp(resource,"cpu")) { - if (!strcmp(direction,"up")) { - handle_cpu_scale_up(jobj_response, source_instance); - } else if (!strcmp(direction,"down")) { - handle_cpu_scale_down(jobj_response, source_instance); - } - } - - // if handle_cpu_scale_up/down is called, program should exit, - // so this is only called when scale up/down are not properly handled. - sprintf(log_msg, "unknown message, resource %s, direction %s", - resource, direction); - -failed: - send_nack(log_msg, source_instance); -} - -// instance_name will be of the form instance-xxxxxxxx -// We want to make a name of the form scale-xxxxxxxx -void instance_to_addr(const char *instance_name, char *addr) -{ - const char *match = "instance-"; - const char *replace = "scale-"; - char *tmp = strstr(instance_name, match); - if (!tmp) { - ERR_LOG("Instance name %s doesn't match expected pattern\n", - instance_name); - exit(-1); - } - strcpy(addr, replace); - strncpy(addr+strlen(replace), instance_name+strlen(match), - UNIX_ADDR_LEN-strlen(replace)-1); - addr[UNIX_ADDR_LEN-1]='\0'; -} - -void handle_message(const char *request, const char *instance_name) -{ - int rc; - fd_set rfds, rfds_tmp; - int fd; - char addr[UNIX_ADDR_LEN]; - - INFO_LOG("handling scaling request: %s", request); - - // Create a unique address from the instance name. When using a helper app - // this is needed in order to handle simultaneous scale events for different - // servers on the same hypervisor. - instance_to_addr(instance_name, addr); - - fd = hg_init(msg_handler, addr, &info); - if (fd == -1) { - if (!info) - ERR_LOG("Unable to allocate memory for info: %m"); - else - ERR_LOG("Unable to initialize guest/host messaging: %s\n", - hg_get_error(info)); - exit(-1); - } - - rc = hg_send_msg(info, SCALE_AGENT_ADDR, instance_name, request); - if (rc < 0) { - ERR_LOG("hg_send_msg failed: %s\n", hg_get_error(info)); - exit(-1); - } - - FD_ZERO(&rfds); - FD_SET(fd, &rfds); - - while(1) { - rfds_tmp = rfds; - rc = select(fd+1, &rfds_tmp, NULL, NULL, NULL); - if (rc > 0) { - if (hg_process_msg(info) < 0) { - ERR_LOG("problem processing messages: %s\n", - hg_get_error(info)); - } - } else if (rc < 0) { - ERR_LOG("select(): %m"); - } - } -} - -void send_nack(char *log_msg, const char *instance_name) -{ - ERR_LOG("sending Nack with error: %s\n", log_msg); - struct json_object *jobj_msg = json_object_new_object(); - if (jobj_msg == NULL) { - ERR_LOG("failed to allocate json object for nack msg\n"); - return; - } - - json_object_object_add(jobj_msg, VERSION, json_object_new_int(CUR_VERSION)); - json_object_object_add(jobj_msg, MSG_TYPE, json_object_new_string(MSG_TYPE_NACK)); - json_object_object_add(jobj_msg, LOG_MSG, json_object_new_string(log_msg)); - - const char *msg = json_object_to_json_string_ext(jobj_msg, JSON_C_TO_STRING_PLAIN); - hg_send_msg(info, SCALE_AGENT_ADDR, instance_name, msg); - - json_object_put(jobj_msg); -} - -void handle_timeout(int sig) -{ - _exit(-2); -} - -void setup_timeout(int timeout_ms) -{ - int rc; - struct itimerval itv; - itv.it_interval.tv_sec = 0; - itv.it_interval.tv_usec = 0; - itv.it_value.tv_sec = 0; - itv.it_value.tv_usec = timeout_ms * 1000; - - // normalize the timer - while(itv.it_value.tv_usec >= 1000000) { - itv.it_value.tv_usec -= 1000000; - itv.it_value.tv_sec += 1; - } - - rc = setitimer(ITIMER_REAL, &itv, NULL); - if (rc < 0) { - ERR_LOG("unable to set timeout"); - exit(-1); - } - - if (signal(SIGALRM, handle_timeout) == SIG_ERR) - ERR_LOG("unable to set timeout handler, continuing anyway: %m"); -} - -struct json_object *create_new_jobj_msg(int timeout_ms, - const char *resource, - const char *direction, - int cpu, - const char *online_cpus) -{ - //validate values - if (timeout_ms < TIMEOUT_OVERHEAD_MS) { - printf("timeout %d too short\n", timeout_ms); - goto invalid_values; - } - - if (strcmp(resource, "cpu")!=0) { - printf("invalid resource %s\n", resource); - goto invalid_values; - } - - struct json_object *jobj_online_cpus; - if (!strcmp(direction, "up")) { - jobj_online_cpus = json_tokener_parse(online_cpus); - if (!json_object_is_type(jobj_online_cpus, json_type_array)) { - printf("invalid online_cpus %s\n", online_cpus); - goto invalid_values; - } - len_request_online_cpus = json_object_array_length(jobj_online_cpus); - request_online_cpus = malloc(len_request_online_cpus*sizeof(int)); - int i; - for (i=0; i< len_request_online_cpus; i++) { - request_online_cpus[i] = json_object_get_int(json_object_array_get_idx(jobj_online_cpus, i)); - } - - } else if (strcmp(direction, "down")!=0) { - printf("invalid direction %s\n", direction); - goto invalid_values; - } - - struct json_object *jobj_msg = json_object_new_object(); - if (jobj_msg == NULL) { - printf("failed to allocate json object for msg\n"); - return NULL; - } - - json_object_object_add(jobj_msg, VERSION, json_object_new_int(CUR_VERSION)); - json_object_object_add(jobj_msg, MSG_TYPE, json_object_new_string(MSG_TYPE_SCALE_REQUEST)); - json_object_object_add(jobj_msg, TIMEOUT_MS, json_object_new_int(timeout_ms - MIN_SCRIPT_TIMEOUT_MS)); - json_object_object_add(jobj_msg, RESOURCE, json_object_new_string(resource)); - json_object_object_add(jobj_msg, DIRECTION, json_object_new_string(direction)); - - if (!strcmp(direction, "up")) { - json_object_object_add(jobj_msg, ONLINE_CPU, json_object_new_int(cpu)); - json_object_object_add(jobj_msg, ONLINE_CPUS, jobj_online_cpus); - } - - return jobj_msg; - -invalid_values: - usage(); - return NULL; -} - -int main(int argc, char *argv[]) -{ - int i; - char *instance_name; - - // msg values - int cpu; - const char *resource; - const char *direction; - const char *request_online_cpus_str = NULL; - - for(i=1;i INSTANCE_NAME_SIZE) { - printf("instance name is too large\n"); - usage(); - } else - instance_name = argv[i]; - } - else { - printf("instance_name option specified without name\n"); - usage(); - } - } else if (0==strcmp(argv[i], "--cpu_add")) { - i++; - if (i, Wind River Systems, Inc. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1) Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2) Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation and/or -* other materials provided with the distribution. -* -* 3) Neither the name of Wind River Systems nor the names of its contributors may be -* used to endorse or promote products derived from this software without specific -* prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#define CUR_VERSION 2 - -#define LOG_MSG_SIZE 100 -#define SCALE_AGENT_ADDR "cgcs.scale" -#define ERRORSIZE 400 - -// keys for guest scaling messages -#define VERSION "version" -#define TIMEOUT_MS "timeout_ms" -#define RESOURCE "resource" -#define DIRECTION "direction" -#define ONLINE_CPU "online_cpu" -#define OFFLINE_CPU "offline_cpu" -#define ONLINE_CPUS "online_cpus" -#define RESULT "result" -#define ERR_MSG "err_msg" -#define MSG_TYPE "msg_type" -#define LOG_MSG "log_msg" // for Nack - -// message types for scaling messages -#define MSG_TYPE_SCALE_REQUEST "scale_request" -#define MSG_TYPE_NACK "nack" - -char errorbuf[ERRORSIZE]; - -#define LOG(priority, format, ...) \ - syslog(priority, "%s(%d): " format, __FILE__, __LINE__, ##__VA_ARGS__) - -#define ERR_LOG(format, ...) \ - do { \ - LOG(LOG_DAEMON|LOG_ERR, format, ##__VA_ARGS__); \ - fprintf(stderr, format, ##__VA_ARGS__); \ - snprintf(errorbuf, sizeof(errorbuf)-1, format, ##__VA_ARGS__); \ - } while (0) - -#define INFO_LOG(format, ...) \ - do { \ - LOG(LOG_DAEMON|LOG_INFO, format, ##__VA_ARGS__); \ - } while (0) - - -struct online_cpus { - int numcpus; - char status[]; -}; - -struct online_cpus *range_to_array(const char *range); -struct json_object *new_json_obj_from_array (struct online_cpus *cpuarray); -void print_array(char *buf, int *array, int len); - diff --git a/guest-agent/guest-scale-agent-2.0/obj/.gitignore b/guest-agent/guest-scale-agent-2.0/obj/.gitignore deleted file mode 100644 index 5e7d2734..00000000 --- a/guest-agent/guest-scale-agent-2.0/obj/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/guest-agent/guest-scale-agent-2.0/parser.c b/guest-agent/guest-scale-agent-2.0/parser.c deleted file mode 100644 index 6a4e2068..00000000 --- a/guest-agent/guest-scale-agent-2.0/parser.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* Copyright (c) <2013-2016>, Wind River Systems, Inc. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1) Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* 2) Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation and/or -* other materials provided with the distribution. -* -* 3) Neither the name of Wind River Systems nor the names of its contributors may be -* used to endorse or promote products derived from this software without specific -* prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include "misc.h" - - -/* Print a range of numbers in a consistent way. */ -char print_range(int start, int end, char *str) -{ - int len; - if (start == end) - len = sprintf(str, "%d,", start); - else - len = sprintf(str, "%d-%d,", start, end); - return len; -} - -void print_array(char *buf, int *array, int len) { - int i; - for(i = 0; i < len; i++) { - sprintf(buf+strlen(buf),"%d,", array[i]); - } - // remove the last comma - buf[strlen(buf)-1]='\0'; -} - -#define BUFLEN 1024 - -/* Takes as input a string representation of online cpus of the form - * "0,1,3-5", and allocates and returns a struct representing whether - * each given cpu is online. - */ -struct online_cpus *range_to_array(const char *range) -{ - struct online_cpus *cpuarray = (struct online_cpus *) malloc(BUFLEN); - int start, end; - int inrange = 0; - char *token, *tmp, *tobe_free; - int done = 0; - tobe_free = strdup(range); - token = tmp = tobe_free; - - if (*tmp == '\0') { - /* empty string, no online cpus */ - cpuarray->numcpus = 0; - free(tobe_free); - return cpuarray; - } - - while (1) { - tmp++; - if (*tmp == '\0') - done = 1; - if (done || (*tmp == ',')) { - /* expect single value or ending a range */ - if (!token) { - ERR_LOG("format error, missing token, unable to parse range\n"); - goto error; - } - *tmp = '\0'; - end = atoi(token); - token = 0; - if (inrange) { - int i; - for (i=start; i<= end; i++) - cpuarray->status[i] = 1; - inrange = 0; - } else { - cpuarray->status[end] = 1; - } - } else if (*tmp == '-') { - if (inrange) { - ERR_LOG("format error, unable to parse range\n"); - goto error; - } - if (!token) { - ERR_LOG("format error, missing token, unable to parse range\n"); - goto error; - } - *tmp = '\0'; - start = atoi(token); - token = 0; - inrange = 1; - } else { - /* expect a numerical value */ - if ((*tmp < '0') || (*tmp > '9')) { - ERR_LOG("format error, expected a numerical value, unable to parse range\n"); - goto error; - } - - if (!token) - token = tmp; - } - if (done) - break; - } - cpuarray->numcpus = end+1; - free(tobe_free); - return cpuarray; -error: - free(cpuarray); - free(tobe_free); - return 0; -} - - -struct json_object *new_json_obj_from_array (struct online_cpus *cpuarray) -{ - int i; - - struct json_object *jobj_array = json_object_new_array(); - if (jobj_array == NULL) { - return NULL; - } - - for (i=0;inumcpus;i++) { - if (cpuarray->status[i]) { - json_object_array_add(jobj_array, json_object_new_int(i)); - } - } - return jobj_array; -} diff --git a/guest-agent/guest-scale-agent-2.0/parser_test.c b/guest-agent/guest-scale-agent-2.0/parser_test.c deleted file mode 100644 index 88cdf1a8..00000000 --- a/guest-agent/guest-scale-agent-2.0/parser_test.c +++ /dev/null @@ -1,67 +0,0 @@ -# -# Copyright(c) 2013-2016, Wind River Systems, Inc. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Wind River Systems nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -#include -#include -#include -#include - -void printstruct(struct online_cpus *cpuarray) -{ - int i; - printf("num cpus: %d\n", cpuarray->numcpus); - for (i=0;inumcpus;i++) - printf("%d: %d\n", i, cpuarray->status[i]); -} - - -struct online_cpus cpus = {15, {1,0,0,0,0,0,1,1,1,0,0,0,1,1,1}}; -int main() -{ - char *str, *str2; - struct online_cpus *newcpus; - printf("initial: \n"); - printstruct(&cpus); - printf("string:\n"); - str = "0,6-8,12-14"; - newcpus = range_to_array(str); - printf("fromstring: \n"); - printstruct(newcpus); - newcpus = range_to_array(""); - printf("empty: \n"); - printstruct(newcpus); - newcpus = range_to_array("0--2"); - newcpus = range_to_array("0-1-2"); - newcpus = range_to_array("0,,2"); - newcpus = range_to_array("0,-2"); - newcpus = range_to_array("1,2-a"); - - return 0; -} diff --git a/guest-agent/guest-scale-agent-2.0/scripts/app_scale_helper b/guest-agent/guest-scale-agent-2.0/scripts/app_scale_helper deleted file mode 100755 index 71bd3898..00000000 --- a/guest-agent/guest-scale-agent-2.0/scripts/app_scale_helper +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash -# -# Copyright(c) 2013-2016, Wind River Systems, Inc. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Wind River Systems nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# This is a basic sample script showing what the script needs to be able to do. -# The script can be edited as needed or replaced by a script or binary that -# works in the same way, or can be deleted entirely if the default behaviour -# of offlining the highest-numbered CPU is satisfactory and you don't care -# about logging scaling events. -# -# We expect to be called in one of the following ways: -# -# "--cpu_add " -# -# This indicates that "cpu" has been set online, and we can now make use of it. -# Do whatever is necessary to start using it, then return 0. -# -# -# "--cpu_del" -# In this case we pick an online cpu to offline, and do whatever we need to in -# order to stop using it, and return the cpu number. Note that CPU 0 must -# always remain online. - -info_log() -{ - logger -p daemon.info -t $0 "$*" - echo $* -} - -err_log() -{ - logger -p daemon.err -t $0 "$*" - echo $* -} - -usage() -{ - err_log "usage: $0 {--cpu_del | --cpu_add }" - exit -1 -} - -cpu_scale_up () -{ - CPU_NUM=$1 - CPU_ONLINE_RANGE=$2 - info_log "cpu add notification, cpu: ${CPU_NUM}" - info_log "cpu_online_range: ${CPU_ONLINE_RANGE}" -} - -cpu_scale_down () -{ - # Make sure host & guest views of offline cpus are consistent - /usr/sbin/offline_cpus - - info_log "cpu del request" - #pick the highest online cpu - CPUS_ONLINE=`cat /sys/devices/system/cpu/online` - CPU_NUM=${CPUS_ONLINE##*[,-]} - - info_log "selected cpu ${CPU_NUM} to offline" - return $CPU_NUM -} - -if [ $# -lt 1 ] -then - usage -elif [ $1 = "--cpu_add" ] -then - if [ $# = 3 ] - then - cpu_scale_up $2 $3 - else - err_log "--cpu_add option called with $# args, expected 3" - usage - fi -elif [ $1 = "--cpu_del" ] -then - cpu_scale_down -else - usage -fi diff --git a/guest-agent/guest-scale-agent-2.0/scripts/guest-scale-agent.service b/guest-agent/guest-scale-agent-2.0/scripts/guest-scale-agent.service deleted file mode 100644 index 3a98f564..00000000 --- a/guest-agent/guest-scale-agent-2.0/scripts/guest-scale-agent.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Guest Scale Agent -After=cloud-init.service -Wants=guest-agent.service - -[Service] -ExecStart=/usr/sbin/guest_scale_agent -Type=simple -Restart=always -RestartSec=0 - -[Install] -WantedBy=multi-user.target diff --git a/guest-agent/guest-scale-agent-2.0/scripts/init_offline_cpus b/guest-agent/guest-scale-agent-2.0/scripts/init_offline_cpus deleted file mode 100644 index 4f2654be..00000000 --- a/guest-agent/guest-scale-agent-2.0/scripts/init_offline_cpus +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/sh -# -# Copyright(c) 2013-2016, Wind River Systems, Inc. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Wind River Systems nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -DAEMON=/usr/sbin/offline_cpus -NAME=offline_cpus -DESC="offline cpus marked offline by hypervisor" -ARGS= - -test -f $DAEMON || exit 0 - -case "$1" in - start) - echo -n "running $DESC: $NAME... " - $DAEMON $ARGS - echo "done." - ;; - stop) - echo -n "stopping $DESC: $NAME... " - echo "done." - ;; - status) - echo -n "$NAME is not running" - ;; - restart) - echo "restarting $DESC: $NAME... " - $0 stop - $0 start - echo "done." - ;; - *) - echo "Usage: $0 {start|stop|status|restart}" - exit 1 - ;; -esac - -exit 0 diff --git a/guest-agent/guest-scale-agent-2.0/scripts/offline-cpus.service b/guest-agent/guest-scale-agent-2.0/scripts/offline-cpus.service deleted file mode 100644 index 3238d4cd..00000000 --- a/guest-agent/guest-scale-agent-2.0/scripts/offline-cpus.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Titanium Cloud agent and helper app to scale VMs up/down -After=cloud-init.service - -[Service] -Type=simple -RemainAfterExit=yes -ExecStart=/etc/init.d/offline_cpus start -ExecStop=/etc/init.d/offline_cpus stop - -[Install] -WantedBy=multi-user.target diff --git a/guest-agent/guest-scale-agent-2.0/scripts/offline_cpus b/guest-agent/guest-scale-agent-2.0/scripts/offline_cpus deleted file mode 100644 index 4d3472fe..00000000 --- a/guest-agent/guest-scale-agent-2.0/scripts/offline_cpus +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash -# -# Copyright(c) 2013-2016, Wind River Systems, Inc. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Wind River Systems nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -# Query the metadata server for the set of cpus that are supposed to be offline -# It will be in the form "set([])" for the empty set, and "set([1, 2, 3])" for the -# non-empty set. -CPUSET_OFFLINE=`wget -t 3 -T 5 -qO - http://169.254.169.254/latest/meta-data/offline_cpuset` -RC=$? -if [ $RC -ne 0 ] -then - logger -p daemon.err "${0}: unable to obtain "offline_cpuset" value. rc: ${RC}" - exit -1 -fi - -OFFLINE_CPUS=`echo ${CPUSET_OFFLINE}|grep -oE [0-9]+` -for CPU in $OFFLINE_CPUS -do - # Offline this cpu to match the underlying virtual machine. - echo 0 > /sys/devices/system/cpu/cpu${CPU}/online - RC=$? - if [ $RC -ne 0 ] - then - logger -p daemon.err "${0}: unable to offline cpu ${CPU}. rc: ${RC}" - exit -1 - fi -done