Skip to content

Commit

Permalink
update c13 to support paid clusters on Fabric 1.04
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Dill committed Aug 22, 2018
1 parent 419c490 commit b5e5c0d
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 45 deletions.
6 changes: 3 additions & 3 deletions Chapter13/cs-offerings/scripts/create/chaincode_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ echo "Creating chaincodeinstall pod"
echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/chaincode_install.yaml"
kubectl create -f ${KUBECONFIG_FOLDER}/chaincode_install.yaml

while [ "$(kubectl get pod -a chaincodeinstall | grep chaincodeinstall | awk '{print $3}')" != "Completed" ]; do
while [ "$(kubectl get pod chaincodeinstall | grep chaincodeinstall | awk '{print $3}')" != "Completed" ]; do
echo "Waiting for chaincodeinstall container to be Completed"
sleep 1;
done

if [ "$(kubectl get pod -a chaincodeinstall | grep chaincodeinstall | awk '{print $3}')" == "Completed" ]; then
if [ "$(kubectl get pod chaincodeinstall | grep chaincodeinstall | awk '{print $3}')" == "Completed" ]; then
echo "Install Chaincode Completed Successfully"
fi

if [ "$(kubectl get pod -a chaincodeinstall | grep chaincodeinstall | awk '{print $3}')" != "Completed" ]; then
if [ "$(kubectl get pod chaincodeinstall | grep chaincodeinstall | awk '{print $3}')" != "Completed" ]; then
echo "Install Chaincode Failed"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ echo "Creating chaincodeinstantiate pod"
echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/chaincode_instantiate.yaml"
kubectl create -f ${KUBECONFIG_FOLDER}/chaincode_instantiate.yaml

while [ "$(kubectl get pod -a chaincodeinstantiate | grep chaincodeinstantiate | awk '{print $3}')" != "Completed" ]; do
while [ "$(kubectl get pod chaincodeinstantiate | grep chaincodeinstantiate | awk '{print $3}')" != "Completed" ]; do
echo "Waiting for chaincodeinstantiate container to be Completed"
sleep 1;
done

if [ "$(kubectl get pod -a chaincodeinstantiate | grep chaincodeinstantiate | awk '{print $3}')" == "Completed" ]; then
if [ "$(kubectl get pod chaincodeinstantiate | grep chaincodeinstantiate | awk '{print $3}')" == "Completed" ]; then
echo "Instantiate Chaincode Completed Successfully"
fi

if [ "$(kubectl get pod -a chaincodeinstantiate | grep chaincodeinstantiate | awk '{print $3}')" != "Completed" ]; then
if [ "$(kubectl get pod chaincodeinstantiate | grep chaincodeinstantiate | awk '{print $3}')" != "Completed" ]; then
echo "Instantiate Chaincode Failed"
fi
12 changes: 6 additions & 6 deletions Chapter13/cs-offerings/scripts/create/create_blockchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,28 @@ while [ "${NUMPENDING}" != "0" ]; do
sleep 1
done

UTILSSTATUS=$(kubectl get pods -a utils | grep utils | awk '{print $3}')
UTILSSTATUS=$(kubectl get pods utils | grep utils | awk '{print $3}')
while [ "${UTILSSTATUS}" != "Completed" ]; do
echo "Waiting for Utils pod to start completion. Status = ${UTILSSTATUS}"
if [ "${UTILSSTATUS}" == "Error" ]; then
echo "There is an error in utils pod. Please run 'kubectl logs utils' or 'kubectl describe pod utils'."
exit 1
fi
UTILSSTATUS=$(kubectl get pods -a utils | grep utils | awk '{print $3}')
UTILSSTATUS=$(kubectl get pods utils | grep utils | awk '{print $3}')
done


UTILSCOUNT=$(kubectl get pods -a utils | grep "0/3" | grep "Completed" | wc -l | awk '{print $1}')
UTILSCOUNT=$(kubectl get pods utils | grep "0/3" | grep "Completed" | wc -l | awk '{print $1}')
while [ "${UTILSCOUNT}" != "1" ]; do
UTILSLEFT=$(kubectl get pods -a utils | grep utils | awk '{print $2}')
UTILSLEFT=$(kubectl get pods utils | grep utils | awk '{print $2}')
echo "Waiting for all containers in Utils pod to complete. Left = ${UTILSLEFT}"
UTILSSTATUS=$(kubectl get pods -a utils | grep utils | awk '{print $3}')
UTILSSTATUS=$(kubectl get pods utils | grep utils | awk '{print $3}')
if [ "${UTILSSTATUS}" == "Error" ]; then
echo "There is an error in utils pod. Please run 'kubectl logs utils' or 'kubectl describe pod utils'."
exit 1
fi
sleep 1
UTILSCOUNT=$(kubectl get pods -a utils | grep "0/3" | grep "Completed" | wc -l | awk '{print $1}')
UTILSCOUNT=$(kubectl get pods utils | grep "0/3" | grep "Completed" | wc -l | awk '{print $1}')
done

echo "Waiting for 15 seconds for peers and orderer to settle"
Expand Down
6 changes: 3 additions & 3 deletions Chapter13/cs-offerings/scripts/create/create_channel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ echo "Creating createchannel pod"
echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/create_channel.yaml"
kubectl create -f ${KUBECONFIG_FOLDER}/create_channel.yaml

while [ "$(kubectl get pod -a createchannel | grep createchannel | awk '{print $3}')" != "Completed" ]; do
while [ "$(kubectl get pod createchannel | grep createchannel | awk '{print $3}')" != "Completed" ]; do
echo "Waiting for createchannel container to be Completed"
sleep 1;
done

if [ "$(kubectl get pod -a createchannel | grep createchannel | awk '{print $3}')" == "Completed" ]; then
if [ "$(kubectl get pod createchannel | grep createchannel | awk '{print $3}')" == "Completed" ]; then
echo "Create Channel Completed Successfully"
fi

if [ "$(kubectl get pod -a createchannel | grep createchannel | awk '{print $3}')" != "Completed" ]; then
if [ "$(kubectl get pod createchannel | grep createchannel | awk '{print $3}')" != "Completed" ]; then
echo "Create Channel Failed"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ echo "Creating composer-card-import pod"
echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/composer-card-import.yaml"
kubectl create -f ${KUBECONFIG_FOLDER}/composer-card-import.yaml

while [ "$(kubectl get pod -a composer-card-import | grep composer-card-import | awk '{print $3}')" != "Completed" ]; do
while [ "$(kubectl get pod composer-card-import | grep composer-card-import | awk '{print $3}')" != "Completed" ]; do
echo "Waiting for composer-card-import container to be Completed"
sleep 1;
done

if [ "$(kubectl get pod -a composer-card-import | grep composer-card-import | awk '{print $3}')" == "Completed" ]; then
if [ "$(kubectl get pod composer-card-import | grep composer-card-import | awk '{print $3}')" == "Completed" ]; then
echo "Composer Card Import Completed Successfully"
fi

if [ "$(kubectl get pod -a composer-card-import | grep composer-card-import | awk '{print $3}')" != "Completed" ]; then
if [ "$(kubectl get pod composer-card-import | grep composer-card-import | awk '{print $3}')" != "Completed" ]; then
echo "Composer Card Import Failed"
fi

Expand Down
6 changes: 3 additions & 3 deletions Chapter13/cs-offerings/scripts/create/join_channel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ echo "Creating joinchannel pod"
echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/join_channel.yaml"
kubectl create -f ${KUBECONFIG_FOLDER}/join_channel.yaml

while [ "$(kubectl get pod -a joinchannel | grep joinchannel | awk '{print $3}')" != "Completed" ]; do
while [ "$(kubectl get pod joinchannel | grep joinchannel | awk '{print $3}')" != "Completed" ]; do
echo "Waiting for joinchannel container to be Completed"
sleep 1;
done

if [ "$(kubectl get pod -a joinchannel | grep joinchannel | awk '{print $3}')" == "Completed" ]; then
if [ "$(kubectl get pod joinchannel | grep joinchannel | awk '{print $3}')" == "Completed" ]; then
echo "Join Channel Completed Successfully"
fi

if [ "$(kubectl get pod -a joinchannel | grep joinchannel | awk '{print $3}')" != "Completed" ]; then
if [ "$(kubectl get pod joinchannel | grep joinchannel | awk '{print $3}')" != "Completed" ]; then
echo "Join Channel Failed"
fi
2 changes: 1 addition & 1 deletion Chapter13/cs-offerings/scripts/delete/delete_blockchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ else
fi

echo "Deleting blockchain deployments"
if [ "$(kubectl get pods -a | grep couchdb | wc -l | awk '{print $1}')" != "0" ]; then
if [ "$(kubectl get pods | grep couchdb | wc -l | awk '{print $1}')" != "0" ]; then
# Use the yaml file with couchdb
echo "Running: kubectl delete -f ${KUBECONFIG_FOLDER}/blockchain-couchdb.yaml"
kubectl delete -f ${KUBECONFIG_FOLDER}/blockchain-couchdb.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ echo "Preparing yaml for chaincodeinstall pod"
sed -e "s/%PEER_ADDRESS%/${PEER_ADDRESS}/g" -e "s/%PEER_MSPID%/${PEER_MSPID}/g" -e "s|%MSP_CONFIGPATH%|${MSP_CONFIGPATH}|g" -e "s/%CHAINCODE_NAME%/${CHAINCODE_NAME}/g" -e "s/%CHAINCODE_VERSION%/${CHAINCODE_VERSION}/g" ${KUBECONFIG_FOLDER}/chaincode_install.yaml.base > ${KUBECONFIG_FOLDER}/chaincode_install.yaml

echo "Deleting Existing Install Chaincode Pod"
if [ "$(kubectl get pods -a | grep chaincodeinstall | wc -l | awk '{print $1}')" != "0" ]; then
if [ "$(kubectl get pods | grep chaincodeinstall | wc -l | awk '{print $1}')" != "0" ]; then
echo "Running: kubectl delete -f ${KUBECONFIG_FOLDER}/chaincode_install.yaml"
kubectl delete -f ${KUBECONFIG_FOLDER}/chaincode_install.yaml

# Wait for the pod to be deleted
while [ "$(kubectl get pods -a | grep chaincodeinstall | wc -l | awk '{print $1}')" != "0" ]; do
while [ "$(kubectl get pods | grep chaincodeinstall | wc -l | awk '{print $1}')" != "0" ]; do
echo "Waiting for old install chaincode Pod to be deleted"
sleep 1;
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ echo "Preparing yaml for chaincode instantiate delete"
sed -e "s/%CHANNEL_NAME%/${CHANNEL_NAME}/g" -e "s/%PEER_ADDRESS%/${PEER_ADDRESS}/g" -e "s/%PEER_MSPID%/${PEER_MSPID}/g" -e "s|%MSP_CONFIGPATH%|${MSP_CONFIGPATH}|g" -e "s/%CHAINCODE_NAME%/${CHAINCODE_NAME}/g" -e "s/%CHAINCODE_VERSION%/${CHAINCODE_VERSION}/g" ${KUBECONFIG_FOLDER}/chaincode_instantiate.yaml.base > ${KUBECONFIG_FOLDER}/chaincode_instantiate.yaml

echo "Deleting Existing Instantiate Chaincode Pod"
if [ "$(kubectl get pods -a | grep chaincodeinstantiate | wc -l | awk '{print $1}')" != "0" ]; then
if [ "$(kubectl get pods | grep chaincodeinstantiate | wc -l | awk '{print $1}')" != "0" ]; then
echo "Running: kubectl delete -f ${KUBECONFIG_FOLDER}/chaincode_instantiate.yaml"
kubectl delete -f ${KUBECONFIG_FOLDER}/chaincode_instantiate.yaml

# Wait for the pod to be deleted
while [ "$(kubectl get pods -a | grep chaincodeinstantiate | wc -l | awk '{print $1}')" != "0" ]; do
while [ "$(kubectl get pods | grep chaincodeinstantiate | wc -l | awk '{print $1}')" != "0" ]; do
echo "Waiting for old instantiate chaincode Pod to be deleted"
sleep 1;
done
Expand Down
8 changes: 4 additions & 4 deletions Chapter13/cs-offerings/scripts/delete/delete_channel-pods.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ echo "Preparing yaml for createchannel pod for deletion"
sed -e "s/%PEER_ADDRESS%/${PEER_ADDRESS}/g" -e "s/%CHANNEL_NAME%/${CHANNEL_NAME}/g" -e "s/%PEER_MSPID%/${PEER_MSPID}/g" ${KUBECONFIG_FOLDER}/create_channel.yaml.base > ${KUBECONFIG_FOLDER}/create_channel.yaml

echo "Deleting Existing Create Channel Pod"
if [ "$(kubectl get pods -a | grep createchannel | wc -l | awk '{print $1}')" != "0" ]; then
if [ "$(kubectl get pods | grep createchannel | wc -l | awk '{print $1}')" != "0" ]; then
echo "Running: kubectl delete -f ${KUBECONFIG_FOLDER}/create_channel.yaml"
kubectl delete -f ${KUBECONFIG_FOLDER}/create_channel.yaml

# Wait for the pod to be deleted
while [ "$(kubectl get pods -a | grep createchannel | wc -l | awk '{print $1}')" != "0" ]; do
while [ "$(kubectl get pods | grep createchannel | wc -l | awk '{print $1}')" != "0" ]; do
echo "Waiting for old Create Channel Pod to be deleted"
sleep 1;
done
Expand All @@ -37,13 +37,13 @@ fi
echo "Preparing yaml for joinchannel pod for deletion"
sed -e "s/%PEER_ADDRESS%/${PEER_ADDRESS}/g" -e "s/%CHANNEL_NAME%/${CHANNEL_NAME}/g" -e "s/%PEER_MSPID%/${PEER_MSPID}/g" -e "s|%MSP_CONFIGPATH%|${MSP_CONFIGPATH}|g" ${KUBECONFIG_FOLDER}/join_channel.yaml.base > ${KUBECONFIG_FOLDER}/join_channel.yaml

if [ "$(kubectl get pods -a | grep joinchannel | wc -l | awk '{print $1}')" != "0" ]; then
if [ "$(kubectl get pods | grep joinchannel | wc -l | awk '{print $1}')" != "0" ]; then
echo "Deleting Existing joinchannel pods"
echo "Running: kubectl delete -f ${KUBECONFIG_FOLDER}/join_channel.yaml"
kubectl delete -f ${KUBECONFIG_FOLDER}/join_channel.yaml

# Wait for the pod to be deleted
while [ "$(kubectl get pods -a | grep joinchannel | wc -l | awk '{print $1}')" != "0" ]; do
while [ "$(kubectl get pods | grep joinchannel | wc -l | awk '{print $1}')" != "0" ]; do
echo "Waiting for old Join Channel to be deleted"
sleep 1;
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ else
fi

echo "Deleting Existing Composer Rest Server pod"
echo "Running: kubectl delete -f ../kube-configs/composer-rest-server.yaml"
kubectl delete -f ../kube-configs/composer-rest-server.yaml
echo "Running: kubectl delete -f ${KUBECONFIG_FOLDER}/composer-rest-server.yaml"
kubectl delete -f ${KUBECONFIG_FOLDER}/composer-rest-server.yaml

while [ "$(kubectl get deployments | grep composer-rest-server | wc -l | awk '{print $1}')" != "0" ]; do
echo "Waiting for composer rest server to be deleted"
Expand Down
2 changes: 1 addition & 1 deletion Chapter13/cs-offerings/scripts/wipe_shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ else
kubectl create -f ../kube-configs/wipe_shared.yaml
fi

while [ "$(kubectl get pod -a wipeshared | grep wipeshared | awk '{print $3}')" != "Completed" ]; do
while [ "$(kubectl get pod wipeshared | grep wipeshared | awk '{print $3}')" != "Completed" ]; do
echo "Waiting for the shared folder to be erased"
sleep 1;
done
Expand Down
1 change: 1 addition & 0 deletions Chapter13/getPEM.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function getPEM ()
cp -v ~/.composer/client-data/PeerAdmin@hlfv1/* $CA_TARGET
cp -v ~/.composer/client-data/PeerAdmin@hlfv1/* ~/.hfc-key-store
KEY_PREFIX=$(cat $CA_TARGET/PeerAdmin | sed -e 's/[}"]*\(.\)[{"]*/\1/g;y/,/\n/' | grep 'signingIdentity:' | sed 's/^.*://')

cp $CA_TARGET/$KEY_PREFIX"-priv" $CA_TARGET/$KEY_PREFIX"_sk"

showStep "Please enter your root password for this O/S now"
Expand Down
43 changes: 32 additions & 11 deletions Chapter13/kubernetes-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ PEERADMIN_CARD=PeerAdmin.card
CARD_SOURCE=~/.composer
CARD_TARGET=cards
IP_ADDRESS="0.0.0.0"
ENV_ADDRESS="0.0.0.0"
COMPOSER_ADDRESS="0.0.0.0"
PAID='false'

while getopts "h:c:k:n:" opt;
while getopts "h:c:k:n:p:" opt;
do
case "$opt" in
h|\?)
Expand All @@ -55,27 +58,45 @@ do
CLUSTER_NAME=$OPTARG
fi
;;
p) showStep "option passed for PAID is: '$OPTARG'"
if [[ $OPTARG != "" ]]; then
PAID=$OPTARG
fi
;;
esac
done

function getContext ()
{
showStep "Retrieving Cluster configuration"
showStep "Retrieving Cluster configuration for $CLUSTER_NAME"
KUBECONFIG=$(bx cs cluster-config $CLUSTER_NAME | grep 'KUBECONFIG' | awk '{print $2}')
echo "KUBECONFIG to export is $KUBECONFIG"
export "$KUBECONFIG"

showStep "Retrieving Kube IP Address"
IP_ADDRESS=$(bx cs workers $CLUSTER_NAME | grep 'kube' | awk '{print $2}')
echo "IP Address is $IP_ADDRESS"
if [[ $PAID == 'false' ]]; then
showStep "Retrieving Kube IP Address for FREE cluster"
IP_ADDRESS=$(bx cs workers $CLUSTER_NAME | grep 'kube' | awk '{print $2}')
ENV_ADDRESS=$IP_ADDRESS
COMPOSER_ADDRESS=$IP_ADDRESS
echo "IP Address is $IP_ADDRESS"
else
showStep "Retrieving CA and COMPOSER IP Addresses for PAID cluster"
# CA_ADDRESS=$(kubectl get pods -o wide | grep 'blockchain-ca' | awk '{print $6}')
COMPOSER_ADDRESS=$(bx cs workers Z2B | grep 'kube' | awk '{print $2}' | head -n1)
CA_ADDRESS=$COMPOSER_ADDRESS
echo "IP Address for CA is $CA_ADDRESS"
echo "IP Address for COMPOSER is $COMPOSER_ADDRESS"
ENV_ADDRESS=$CA_ADDRESS
fi

showStep "updating env.json for $OS"
if [[ $OS == "Darwin" ]] || [[ $OS == "darwin" ]]; then
echo "updating for OSX"
cat controller/env.json | sed -i '.bak' 's/\"kube_address":".*"/"kube_address":"'$IP_ADDRESS'"/' controller/env.json
pwd
cat controller/env.json | sed -i '.bak' 's/\"kube_address":".*"/"kube_address":"'$ENV_ADDRESS'"/' controller/env.json
else
echo "updating for Linux"
cat controller/env.json | sed -i 's/\"kube_address":".*"/"kube_address":"'$IP_ADDRESS'"/' controller/env.json
cat controller/env.json | sed -i 's/\"kube_address":".*"/"kube_address":"'$ENV_ADDRESS'"/' controller/env.json
fi
}

Expand Down Expand Up @@ -114,7 +135,7 @@ function pauseForCard ()
{
CURRENT=$(pwd)
echo -e "${RESET} pausing while you go to composer playground and download the PeerAdmin card."
echo -e "${GREEN}You can access the playground at ==> http://$IP_ADDRESS:31080${RESET}"
echo -e "${GREEN}You can access the playground at ==> http://$COMPOSER_ADDRESS:31080${RESET}"
echo -e "Click on ${GREEN}Launch Now${RESET} and then ${GREEN}export the PeerAdmin card ${RESET}"
echo -e "after downloading the PeerAdmin card, ${GREEN}please copy it into your $CURRENT folder.${RESET}"

Expand All @@ -125,9 +146,9 @@ function pauseForCard ()
fi
while [ ! -f $PEERADMIN_CARD ]; do
if [ $(which xdg-open | grep 'xdg-open' -c ) -eq 0 ]; then
open http://$IP_ADDRESS:31080
open http://$COMPOSER_ADDRESS:31080
else
xdg-open http://$IP_ADDRESS:31080
xdg-open http://$COMPOSER_ADDRESS:31080
fi
read -n1 -r -p "And then press any key to continue..." key
done
Expand All @@ -137,7 +158,7 @@ function updateCard ()
{
showStep "updating $CURRENT/$PEERADMIN_CARD"
pushd ./cs-offerings/scripts/connection-profile
./update_card.sh -c $CURRENT/$PEERADMIN_CARD -a $IP_ADDRESS
./update_card.sh -c $CURRENT/$PEERADMIN_CARD -a $COMPOSER_ADDRESS
popd
composer card import --file $PEERADMIN_CARD
composer card list
Expand Down
2 changes: 1 addition & 1 deletion Chapter13/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ applications:
memory: 256M
instances: 1
route: {your-globally-unique-application-name-here}.mybluemix.net
name: Z2B on Kubernetes
name: {your-globally-unique-application-name-here}
disk_quota: 1024M

0 comments on commit b5e5c0d

Please sign in to comment.