This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
[Do Not Merge] Add LXD container build scripts for Alcor services #746
Open
VanderChen
wants to merge
10
commits into
futurewei-cloud:master
Choose a base branch
from
VanderChen:service-lxd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d7594dc
Add LXD yaml file for DPM
VanderChen 3475052
Add distrobuilder doc and yaml files for each services
VanderChen 0d27fbb
Update lxd scripts
a9aaab1
Update lxd build shell and lxd yaml file
VanderChen 9ae2969
Fix bug in lxd scripts
VanderChen 98cb187
Fix bug in lxd scripts
VanderChen ab20aa3
Fix bug in lxd scripts
VanderChen 3501278
Fix bug in lxd scripts
VanderChen 6f936bc
Fix bug in lxd scripts
VanderChen aca67e0
Add static ip config for lxd container
VanderChen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
= Introduction of deployment in LXD | ||
Min Chen <[email protected]> | ||
v0.1, 2020-09-18 | ||
:toc: right | ||
:sectnums: | ||
:imagesdir: images | ||
|
||
== Install LXD and disrtibuilder | ||
|
||
== Build LXD container images | ||
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VanderChen Can you add more description to show how to use these scripts? Thanks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,291 @@ | ||
#!/bin/bash | ||
|
||
# MIT License | ||
# Copyright(c) 2020 Futurewei Cloud | ||
# | ||
# Permission is hereby granted, | ||
# free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, | ||
# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons | ||
# to whom the Software is furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
LXD_SCRIPTS_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
ALCOR_ROOT_DIR=$(dirname $(dirname $LXD_SCRIPTS_PATH)) | ||
IGNITE_VERSION="2.10.0" | ||
declare -a services_list=(vpm snm rm pim mm pm nm sgm ag dpm eim qm nam ncm gm) | ||
declare -a ip_list=(10.92.85.101 10.92.85.102 10.92.85.103 10.92.85.104 10.92.85.105 10.92.85.106 10.92.85.107 10.92.85.108 10.92.85.109 10.92.85.110) | ||
|
||
function install_distrobuilder { | ||
echo "Install distrobuilder dependencis" | ||
apt update && \ | ||
apt install -y \ | ||
debootstrap \ | ||
rsync \ | ||
gpg \ | ||
squashfs-tools \ | ||
git | ||
wget https://dl.google.com/go/go1.18.1.linux-amd64.tar.gz && \ | ||
rm -rf /usr/local/go && \ | ||
tar -C /usr/local -xzf go1.18.1.linux-amd64.tar.gz | ||
rm go1.18.1.linux-amd64.tar.gz | ||
PATH=$PATH:/usr/local/go/bin | ||
git clone https://github.com/lxc/distrobuilder && \ | ||
cd ./distrobuilder && \ | ||
make | ||
cd .. | ||
rm -rf distrobuilder | ||
} | ||
|
||
function init_lxd { | ||
echo "Install LXD" | ||
apt install -y lxd && \ | ||
lxd init | ||
} | ||
|
||
function build_alcor_image () { | ||
tee -a $1/ignite.service > /dev/null <<EOF | ||
[Unit] | ||
Description=Apache Ignite Daemon | ||
After=syslog.target network.target | ||
Wants=network.target | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/root/ignite/bin/ignite.sh | ||
RestartSec=1min | ||
KillMode=control-group | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
EOF | ||
|
||
tee -a $1/${2}.service > /dev/null <<EOF | ||
[Unit] | ||
Description=alcor-service Daemon | ||
After=syslog.target network.target | ||
Wants=network.target | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/bin/java -jar /root/alcor-service.jar \ | ||
--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED \ | ||
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED \ | ||
--add-exports=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED \ | ||
--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED \ | ||
--add-exports=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED \ | ||
--illegal-access=permit | ||
RestartSec=1min | ||
KillMode=control-group | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
EOF | ||
|
||
sed -i "s/alcor-service.jar/${3}/g" $1/${2}.service > /dev/null | ||
|
||
cd $1 && \ | ||
cp -rp $LXD_SCRIPTS_PATH/apache-ignite-${IGNITE_VERSION}-bin ignite && \ | ||
$HOME/go/bin/distrobuilder build-lxd lxd.yaml && \ | ||
lxc image import lxd.tar.xz rootfs.squashfs --alias ${2} && \ | ||
rm -rf lxd.tar.xz \ | ||
rootfs.squashfs \ | ||
*.service \ | ||
ignite && \ | ||
echo | ||
} | ||
|
||
function config_alcor_service_url () { | ||
sed -i -E "s/('microservices.vpc.service.url'.+)name(.+'9001/')/\1'=http://10.92.85.101:'\2/" ${1}/src/main/resources/application.properties | ||
sed -i -E "s/('microservices.subnet.service.url'.+)name(.+'9002/')/\1'=http://10.92.85.102'\2/" ${1}/src/main/resources/application.properties | ||
sed -i -E "s/('microservices.route.service.url'.+)name(.+'9003/')/\1'=http://10.92.85.103'\2/" ${1}/src/main/resources/application.properties | ||
sed -i -E "s/('microservices.port.service.url'.+)name(.+'9006/')/\1'=http://10.92.85.104'\2/" ${1}/src/main/resources/application.properties | ||
sed -i -E "s/('microservices.sg.service.url'.+)name(.+'9008/')/\1'=http://0.92.85.105'\2/" ${1}/src/main/resources/application.properties | ||
sed -i -E "s/('microservices.elasticip.service.url'.+)name(.+'9011/')/\1'=http://10.92.85.106'\2/" ${1}/src/main/resources/application.properties | ||
sed -i -E "s/('microservices.quota.service.url'.+)name(.+'9012/')/\1'=http://10.92.85.107'\2/" ${1}/src/main/resources/application.properties | ||
sed -i -E "s/('microservices.dpm.service.url'.+)name(.+'9010/')/\1'=http://10.92.85.108'\2/" ${1}/src/main/resources/application.properties | ||
} | ||
|
||
function config_alcor_container_url () { | ||
count=0 | ||
echo "Starting Alcor LXD containers\n" | ||
for i in "${!services_list[@]}"; do | ||
lxc stop "${services_list[$i]}" | ||
lxc network attach $1 "${services_list[$i]}" eth0 eth0 | ||
lxc config device set "${services_list[$i]}" eth0 ipv4.address "${ip_list[$i]}" | ||
lxc start "${services_list[$i]}" | ||
if [[ $? -eq 0 ]]; then count=$((count + 1)); fi | ||
done | ||
echo -e "\n$count services started...\n" | ||
} | ||
|
||
function build_alcor_lxd_images_with_db { | ||
echo "Build Alcor LXD container" | ||
|
||
apt install -y zip | ||
|
||
cd ${ALCOR_ROOT_DIR} | ||
mvn -Dmaven.test.skip=true -DskipTests clean package install | ||
|
||
# download Apache Ignite | ||
cd ${LXD_SCRIPTS_PATH} | ||
wget https://archive.apache.org/dist/ignite/${IGNITE_VERSION}/apache-ignite-${IGNITE_VERSION}-bin.zip | ||
unzip apache-ignite-${IGNITE_VERSION}-bin.zip | ||
rm apache-ignite-${IGNITE_VERSION}-bin.zip | ||
|
||
#build images | ||
|
||
echo "#1 Creating vpc_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/vpc_manager vpm vpcmanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#2 Creating subnet_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/subnet_manager snm subnetmanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#3 Creating route_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/route_manager rm routemanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#4 Creating private_ip_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/subnet_manager pim subnetmanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#5 Creating mac_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/mac_manager mm macmanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#6 Creating port_manger lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/port_manager pm portmanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#7 Creating node_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/node_manager nm nodemanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#8 Creating security_group_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/security_group_manager sgm securitygroupmanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#9 Creating api_gateway lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/api_gateway ag apigateway-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#10 Creating data_plane_manager lxd image\n" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/data_plane_manager dpm dataplanemanager-0.1.0-SNAPSHOT.jar | ||
|
||
echo "#11 Creating elastic_ip_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/elastic_ip_manager eim elastic_ip_manager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#12 Creating quoto_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/quota_manager qm quotamanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#13 Creating network_acl_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/network_acl_manager nam networkaclmanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#14 Creating network_acl_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/network_config_manager ncm networkconfigmanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
echo "#15 Creating gateway_manager lxd image" | ||
build_alcor_image $ALCOR_ROOT_DIR/services/gateway_manager gm gatewaymanager-0.1.0-SNAPSHOT.jar | ||
echo | ||
|
||
rm -rf $LXD_SCRIPTS_PATH/apache-ignite-2.10.0-bin | ||
} | ||
|
||
function start_lxd_containers { | ||
count=0 | ||
echo "Starting Alcor LXD containers\n" | ||
for service in ${services_list[@]}; do | ||
lxc launch $service $service | ||
sleep 5 | ||
lxc exec $service -- bash -c "chmod +x /root/ignite/bin/ignite.sh" | ||
lxc exec $service -- bash -c "systemctl enable ignite" | ||
lxc exec $service -- bash -c "systemctl enable $service" | ||
lxc exec $service -- bash -c "systemctl start ignite" | ||
lxc exec $service -- bash -c "systemctl start $service" | ||
if [[ $? -eq 0 ]]; then count=$((count + 1)); fi | ||
done | ||
echo -e "\n$count services started...\n" | ||
} | ||
|
||
function stop_lxd_containers { | ||
count=0 | ||
echo "Stoping and Deleting Alcor LXD containers\n" | ||
for service in ${services_list[@]}; do | ||
lxc stop $servicebash | ||
if [[ $? -eq 0 ]]; then count=$((count + 1)); fi | ||
done | ||
echo -e "\n$count services stoped and deleted...\n" | ||
} | ||
|
||
function delete_lxd_containers { | ||
count=0 | ||
echo "Stoping and Deleting Alcor LXD containers\n" | ||
for service in ${services_list[@]}; do | ||
lxc delete $service | ||
if [[ $? -eq 0 ]]; then count=$((count + 1)); fi | ||
done | ||
echo -e "\n$count services stoped and deleted...\n" | ||
} | ||
|
||
function delete_lxd_images { | ||
count=0 | ||
echo "Deleting Alcor LXD images\n" | ||
for service in ${services_list[@]}; do | ||
lxc stop $service $service | ||
lxc delete $service | ||
if [[ $? -eq 0 ]]; then count=$((count + 1)); fi | ||
done | ||
echo -e "\n$count services images stoped...\n" | ||
} | ||
|
||
|
||
|
||
while getopts "iIbsrdD" opt; do | ||
case $opt in | ||
i) | ||
install_distrobuilder | ||
;; | ||
I) | ||
init_lxd | ||
;; | ||
b) | ||
build_alcor_lxd_images_with_db | ||
;; | ||
s) | ||
start_lxd_containers | ||
;; | ||
r) | ||
stop_lxd_containers | ||
;; | ||
d) | ||
delete_lxd_containers | ||
;; | ||
D) | ||
delete_lxd_images | ||
;; | ||
\?) | ||
echo "Invalid arguements" | ||
;; | ||
esac | ||
done | ||
|
||
if [ $OPTIND -eq 1 ]; then | ||
echo "Build and start containers" | ||
stop_lxd_containers | ||
delete_lxd_images | ||
build_alcor_lxd_images_with_db | ||
start_lxd_containers | ||
fi | ||
shift $((OPTIND-1)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VanderChen Please give some paragraphs here to describe how to use those scripts in this folder.