Bug 1007455

Summary: Cartridge sdk should expose a function to get the primary endpoint for a gear
Product: OpenShift Online Reporter: Paul Morie <pmorie>
Component: ContainersAssignee: Michal Fojtik <mfojtik>
Status: CLOSED CURRENTRELEASE QA Contact: libra bugs <libra-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 2.xCC: chunchen, dmcphers, jhonce, mfojtik
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-10-17 13:28:35 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Paul Morie 2013-09-12 14:10:18 UTC
Currently the haproxy cartridge uses grep to search the manifest for the web framework cartridge in an app.  Instead, the cartridge sdk should expose a function for this, backed by an oo- script which actually parses the manifest.

Comment 1 Michal Fojtik 2013-09-18 12:19:40 UTC
While I'm working on the oo- script for parsing the cartridge manifest, I discovered that the haproxy grep/sed/tr magic could be replaced by a bash function in the OpenShift Bash SDK:

function primary_cart_manifest {
  ruby -ryaml -e "p YAML.load_file('$OPENSHIFT_PRIMARY_CARTRIDGE_DIR/metadata/manifest.yml')$1"
}

Then you can call this function using:

first_ip_in_manifest=$(primary_cart_manifest "['Endpoints'].first['Private-IP-Name']")

If you look at v2_cart_model.rb 'primary_cartridge' method, this function is not very different
as what the method is doing.

The difficulty I have with creating the oo- script for manifest parsing is the YAML format
of the manifest... You need to deal with things like Array's and Hash'es, so the syntax
could be pretty wild:

$ oo-cartridge-manifest -c 52398bc711fae092a1000007 primary -n 'Private-IP-Name' --endpoint 1

The same applies for other properties in manifest.yaml (--compatible-versions, etc..) Basically
the oo- script will need to map the YAML keys into 'options', which might turn into maintenance
nightmare ;-)

What do you guys think?

Comment 2 openshift-github-bot 2013-09-24 15:09:20 UTC
Commit pushed to master at https://github.com/openshift/origin-server

https://github.com/openshift/origin-server/commit/086363bdce6736849064e3a683ca1294a9fdec34
Bug 1007455 - Added primary_cartridge methods to Ruby SDK

Comment 3 chunchen 2013-09-25 04:38:04 UTC
It's fixed, verified on devenv_3821, please refer to the following results:

1. Create a scaled app
rhc app create cpl0s0 perl-5.1 -s --no-git
2. SSH into this app
rhc ssh cpl0s0
3. Check scripts code
grep -e first_ip_in_manifest -e first_port_in_manifest haproxy/hooks/set-proxy
4. Check the primary endpoint variables
env |grep  PERL

at step 3: 
    first_ip_in_manifest=$(primary_cartridge_private_ip_name)
    prim_cart_ip="OPENSHIFT_${prim_cart}_${first_ip_in_manifest}"
    first_port_in_manifest=$(primary_cartridge_private_port_name)
    prim_cart_port="OPENSHIFT_${prim_cart}_${first_port_in_manifest}"

at step 4:
OPENSHIFT_PERL_VERSION=5.10
PERL5LIB=/var/lib/openshift/52424f7e617cec7634000007/app-root/runtime/repo/libs:/var/lib/openshift/52424f7e617cec7634000007/perl/perl5lib/lib/perl5/
OPENSHIFT_PERL_IDENT=redhat:perl:5.10:0.0.5
OPENSHIFT_PERL_PROXY_PORT=38031
OPENSHIFT_PERL_PORT=8080
OPENSHIFT_PERL_DIR=/var/lib/openshift/52424f7e617cec7634000007/perl/
OPENSHIFT_PERL_IP=127.1.244.1
OPENSHIFT_PERL_LOG_DIR=/var/lib/openshift/52424f7e617cec7634000007/perl//logs/