Skip to content

Commit

Permalink
GlassFish - Added 3.0 support
Browse files Browse the repository at this point in the history
* src/platform/glassfish/*.py
  -- this was miserable to implement, mainly because they changed the REST
  interface so much between 3.0 and 3.1.
  • Loading branch information
hatRiot committed Jul 12, 2014
1 parent 436c8fa commit c86c0ee
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/platform/glassfish/authenticate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def checkAuth(ip, port, title):

if title == GINTERFACES.GAD:

url = 'https://{0}:{1}/management/domain'.format(ip, port)
url = 'http://{0}:{1}/management/domain'.format(ip, port)

# check with given auth
if state.usr_auth:
Expand Down
27 changes: 27 additions & 0 deletions src/platform/glassfish/auxiliary/list_wars.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def run(self, fingerengine, fingerprint):
LOG.ERROR)
return

if fingerprint.version in ['3.0']:
base = base.replace('https', 'http')
uri = '/management/domain/applications/application'
return self._parse_old(base + uri, cookie)


response = utility.requests_get(base+uri, auth=cookie, headers=headers)
if response.status_code is 200:

Expand All @@ -52,3 +58,24 @@ def run(self, fingerengine, fingerprint):
utility.Msg("Discovered %d deployed apps" % len(data['properties']))
for entry in data['properties'].keys():
utility.Msg(' /%s' % entry)

def _parse_old(self, url, cookie):
""" Of course 3.0 doesn't expose list-applications ...
"""

headers = {
"Accept" : "application/json",
"X-Requested-By" : "requests"
}

response = utility.requests_get(url, auth=cookie, headers=headers)
if response.status_code is 200:

data = json.loads(response.content)
if not u"Child Resources" in data.keys():
utility.Msg("No apps found")
return

for entry in data[u"Child Resources"]:
splt = entry.rsplit('/',1 )[1]
utility.Msg(" /%s" % splt)
36 changes: 30 additions & 6 deletions src/platform/glassfish/deployers/admin_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
from src.module.deploy_utils import parse_war_path
from os.path import abspath
from log import LOG
import state
import utility
import json


versions = ['3.1', '4.0']
versions = ['3.0', '3.1', '4.0']
title = GINTERFACES.GAD
def deploy(fingerengine, fingerprint):
""" Upload via the exposed REST API
"""

if fingerprint.version in ['3.1', '4.0']:
state.ssl = True

war_file = fingerengine.options.deploy
war_path = abspath(war_file)
war_name = parse_war_path(war_file)
Expand All @@ -29,19 +33,39 @@ def deploy(fingerengine, fingerprint):
return

utility.Msg("Preparing to deploy {0}...".format(war_file))
base = 'https://{0}:{1}/management/domain/applications/application'\
.format(dip, fingerprint.port)
base = 'http://{0}:{1}'.format(dip, fingerprint.port)
uri = '/management/domain/applications/application'

data = {
"id" : open(war_path, 'rb'),
'id' : open(war_path, 'rb'),
'force' : 'true'
}

response = utility.requests_post(base, files=data,
response = utility.requests_post(base + uri, files=data,
auth=cookie,
headers=headers)
if response.status_code is 200:
utility.Msg("Deployed {0} to :8080/{0}".format(war_name), LOG.SUCCESS)

if fingerprint.version in ['3.0']:

# GF 3.0 ignores context-root and appends a random character string to
# the name. We need to fetch it, then set it as our random_int for
# invoke support. There's also no list-wars in here...
url = base + '/management/domain/applications/application'
response = utility.requests_get(url, auth=cookie, headers=headers)
if response.status_code is 200:

data = json.loads(response.content)
for entry in data[u"Child Resources"]:
if war_name in entry:
rand = entry.rsplit('/', 1)[1]
rand = rand.split(war_name)[1]
fingerengine.random_int = str(rand)

utility.Msg("Deployed {0} to :8080/{0}{1}".format(war_name, rand),
LOG.SUCCESS)
else:
utility.Msg("Deployed {0} to :8080/{0}".format(war_name), LOG.SUCCESS)
else:
utility.Msg("Failed to deploy {0} (HTTP {1})".format(war_name,
response.status_code),
Expand Down
8 changes: 8 additions & 0 deletions src/platform/glassfish/fingerprints/Glass3Admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from src.platform.glassfish.interfaces import ManagerInterface


class FPrint(ManagerInterface):

def __init__(self):
super(FPrint, self).__init__()
self.version = '3.0'
1 change: 1 addition & 0 deletions src/platform/glassfish/fingerprints/GlassHeaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def check(self, ip, port = None):
"""

versions = {
"Oracle GlassFish Server 3.0" : "3.0",
"GlassFish Server Open Source Edition 3.1" : "3.1",
"GlassFish Server Open Source Edition 4.0" : "4.0"
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/glassfish/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def check(self, ip, port = None):
response = utility.requests_get(url)
if response.status_code == 404:

data = findall("Edition (.*?) *</h3>", response.content)
data = findall("Edition|Server (.*?) *</h3>", response.content)
if len(data) > 0 and self.version in data[0]:

#
Expand Down
21 changes: 18 additions & 3 deletions src/platform/glassfish/undeployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
from src.platform.glassfish.interfaces import GINTERFACES
from src.module.deploy_utils import parse_war_path
from log import LOG
import state
import utility

titles = [GINTERFACES.GAD]
def undeploy(fingerengine, fingerprint):
""" Undeploying is quite simple via the exposed REST API
"""

base = 'https://{0}:{1}'.format(fingerengine.options.ip,
if fingerprint.version in ['3.1', '4.0']:
state.ssl = True

base = 'http://{0}:{1}'.format(fingerengine.options.ip,
fingerprint.port)
context = parse_war_path(fingerengine.options.undeploy)
cookie = checkAuth(fingerengine.options.ip, fingerprint.port,
Expand All @@ -27,8 +31,19 @@ def undeploy(fingerengine, fingerprint):
utility.Msg("Preparing to undeploy %s..." % context)
uri = '/management/domain/applications/application/%s' % context

response = utility.requests_delete(base + uri, auth=cookie,
headers=headers)
if fingerprint.version in ['3.0']:

# GF 3.0 doesnt appear to support the DELETE verb
data = {
"operation" : "__deleteoperation"
}

response = utility.requests_post(base + uri, auth=cookie,
headers=headers,
data=data)
else:
response = utility.requests_delete(base + uri, auth=cookie,
headers=headers)

if response.status_code is 200:
utility.Msg("'%s' undeployed successfully" % context, LOG.SUCCESS)
Expand Down

0 comments on commit c86c0ee

Please sign in to comment.