From a0125edd1063359eb319f1ab0bf2e988051a5781 Mon Sep 17 00:00:00 2001 From: Joris De Winne Date: Mon, 15 Aug 2016 20:26:43 -0700 Subject: [PATCH] Refactoring into REST api --- README.md | 8 +- build.gradle | 14 +- .../caucho/quercus/StringBuilderStream.java | 37 -- src/main/java/com/caucho/quercus/XLREnv.java | 50 --- .../java/com/caucho/quercus/XLRQuercus.java | 61 ---- .../java/net/collegeman/phpinjava/PHP.java | 337 ------------------ .../net/collegeman/phpinjava/PHPObject.java | 83 ----- src/main/resources/ispw/ISPWClient.py | 73 ++++ src/main/resources/ispw/ISPWClientUtil.py | 14 + src/main/resources/ispw/__init__.py | 0 src/main/resources/ispw/createRelease.py | 5 + src/main/resources/ispw/deploy.py | 6 + src/main/resources/ispw/promote.py | 6 + src/main/resources/ispwHttp/HttpRequest.py | 217 +++++++++++ src/main/resources/ispwHttp/__init__.py | 0 src/main/resources/synthetic.xml | 56 ++- .../web/include/ISPWTile/js/ispw-tile.js | 2 +- src/main/resources/xlrelease/phpRequest.py | 21 -- 18 files changed, 354 insertions(+), 636 deletions(-) delete mode 100644 src/main/java/com/caucho/quercus/StringBuilderStream.java delete mode 100644 src/main/java/com/caucho/quercus/XLREnv.java delete mode 100644 src/main/java/com/caucho/quercus/XLRQuercus.java delete mode 100644 src/main/java/net/collegeman/phpinjava/PHP.java delete mode 100644 src/main/java/net/collegeman/phpinjava/PHPObject.java create mode 100644 src/main/resources/ispw/ISPWClient.py create mode 100644 src/main/resources/ispw/ISPWClientUtil.py create mode 100644 src/main/resources/ispw/__init__.py create mode 100644 src/main/resources/ispw/createRelease.py create mode 100644 src/main/resources/ispw/deploy.py create mode 100644 src/main/resources/ispw/promote.py create mode 100644 src/main/resources/ispwHttp/HttpRequest.py create mode 100644 src/main/resources/ispwHttp/__init__.py delete mode 100644 src/main/resources/xlrelease/phpRequest.py diff --git a/README.md b/README.md index fe7e1cd..e182d8a 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,8 @@ See the **[XL Release Documentation](https://docs.xebialabs.com/xl-release/index # Installation # * Minimal version XLR: 5.0.0+ -* Install the [php-in-java](https://github.com/jdewinne/php-in-java) jar under lib -* Install [resin-util](http://caucho.com/m2/com/caucho/resin-util/3.2.1/resin-util-3.2.1.jar) under lib -* Install [com.caucho:quercus:4.0.45](http://central.maven.org/maven2/com/caucho/quercus/4.0.45/quercus-4.0.45.jar) under lib ## Tasks ## -+ wzRequest - * `action` \ No newline at end of file ++ CreateRelease ++ Promote ++ Deploy \ No newline at end of file diff --git a/build.gradle b/build.gradle index e4a9556..3c45c99 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id "com.github.hierynomus.license" version "0.12.1" + id "com.xebialabs.xlr.docker" version "1.1.10" } apply plugin: 'java' @@ -7,19 +8,12 @@ apply plugin: 'idea' apply plugin: 'eclipse' apply plugin: 'maven' -version="1.1.0" +version="2.0.0" -repositories { - mavenLocal() - mavenCentral() +xlrDocker { + version = '5.0.1.9' } -dependencies { - compile 'com.caucho:quercus:4.0.45' - compile 'org.apache.commons:commons-lang3:3.4' -} - - license { header rootProject.file('src/main/license/xebialabs_community.license') strictCheck true diff --git a/src/main/java/com/caucho/quercus/StringBuilderStream.java b/src/main/java/com/caucho/quercus/StringBuilderStream.java deleted file mode 100644 index fd7ccd4..0000000 --- a/src/main/java/com/caucho/quercus/StringBuilderStream.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.caucho.quercus; - -import com.caucho.vfs.StreamImpl; - -import java.io.IOException; - -public class StringBuilderStream extends StreamImpl { - private static StringBuilderStream _builder; - public StringBuilder output; - - private StringBuilderStream() { - } - - public static com.caucho.quercus.StringBuilderStream create() { - if(_builder == null) { - _builder = new StringBuilderStream(); - _builder.output = new StringBuilder(); - } - - return _builder; - } - - public boolean canWrite() { - return true; - } - - public void write(byte[] buf, int offset, int length, boolean isEnd) throws IOException { - String text2 = new String(buf, "ISO-8859-1"); - output.append(text2.toCharArray(),offset,length); - } - - @Override - public String toString() { - return output.toString(); - } - -} \ No newline at end of file diff --git a/src/main/java/com/caucho/quercus/XLREnv.java b/src/main/java/com/caucho/quercus/XLREnv.java deleted file mode 100644 index 23d0ba0..0000000 --- a/src/main/java/com/caucho/quercus/XLREnv.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.caucho.quercus; - -import com.caucho.quercus.env.CliEnv; -import com.caucho.quercus.env.LongValue; -import com.caucho.quercus.env.NullValue; -import com.caucho.quercus.env.Value; -import com.caucho.quercus.page.QuercusPage; -import com.caucho.vfs.WriteStream; - -import java.io.IOException; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Created by jdewinne on 5/18/16. - */ -public class XLREnv extends CliEnv { - private static final Logger log = Logger.getLogger(XLREnv.class.getName()); - - public XLREnv(QuercusContext quercus, QuercusPage page, WriteStream out, String[] argv) { - super(quercus, page, out, argv); - } - - @Override - public Value exit(Value msg) { - if(!msg.isNull() && !(msg instanceof LongValue)) { - try { - this.getOut().print(msg.toString()); - } catch (IOException var3) { - log.log(Level.WARNING, var3.toString(), var3); - } - - throw new QuercusExitException(msg.toString() + "\n" + this.getStackTraceAsString()); - } else { - if(!msg.isNull()) { - // When we get exit code 0 - if (Objects.equals(msg.toString(), "0")) { - return NullValue.NULL; - } - } - return this.exit(); - } - } - - @Override - public Value exit() { - throw new QuercusExitException(this.getStackTraceAsString()); - } -} diff --git a/src/main/java/com/caucho/quercus/XLRQuercus.java b/src/main/java/com/caucho/quercus/XLRQuercus.java deleted file mode 100644 index a6a89bb..0000000 --- a/src/main/java/com/caucho/quercus/XLRQuercus.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 1998-2012 Caucho Technology -- all rights reserved - * - * This file is part of Resin(R) Open Source - * - * Each copy or derived work must preserve the copyright notice and this - * notice unmodified. - * - * Resin Open Source is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Resin Open Source is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty - * of NON-INFRINGEMENT. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with Resin Open Source; if not, write to the - * - * Free Software Foundation, Inc. - * 59 Temple Place, Suite 330 - * Boston, MA 02111-1307 USA - * - * @author Nam Nguyen - */ - -package com.caucho.quercus; - -import com.caucho.quercus.env.Env; -import com.caucho.quercus.page.QuercusPage; -import com.caucho.quercus.servlet.api.QuercusHttpServletRequest; -import com.caucho.quercus.servlet.api.QuercusHttpServletResponse; -import com.caucho.vfs.WriteStream; - -public class XLRQuercus extends Quercus -{ - @Override - public Env createEnv(QuercusPage page, - WriteStream out, - QuercusHttpServletRequest request, - QuercusHttpServletResponse response) - { - return new XLREnv(this, page, out, getArgv()); - } - - public void processArguments(String [] args) { - super.parseArgs(args); - - } - - /** - * Hard-coded to true for CLI according to php.net. - */ - @Override - public boolean isRegisterArgv() { - return true; - } -} \ No newline at end of file diff --git a/src/main/java/net/collegeman/phpinjava/PHP.java b/src/main/java/net/collegeman/phpinjava/PHP.java deleted file mode 100644 index 342aedf..0000000 --- a/src/main/java/net/collegeman/phpinjava/PHP.java +++ /dev/null @@ -1,337 +0,0 @@ -package net.collegeman.phpinjava; - -/** - * PHP-in-Java PHP wrapper for Java and Groovy. - * Copyright (C) 2009-2010 Collegeman.net, LLC. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -import com.caucho.quercus.*; -import com.caucho.quercus.env.*; -import com.caucho.quercus.page.QuercusPage; -import com.caucho.quercus.servlet.api.QuercusHttpServletRequest; -import com.caucho.quercus.servlet.api.QuercusHttpServletResponse; -import com.caucho.vfs.FilePath; -import com.caucho.vfs.StringStream; -import com.caucho.vfs.WriteStream; -import org.apache.commons.lang3.ArrayUtils; - -import java.io.*; -import java.net.URL; -import java.net.URLConnection; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - *

Instances of this class wrap one or more PHP scripts, making it possible for - * those scripts to be compiled into memory and

- * - *

Also, once instantiated, the PHP object can be used to compile and cache - * arbitrary snippets of PHP into a single PHP script.

- *

Quercus and Resin versus PHP-in-Java

- *

Our PHP-in-Java library is built on top of Quercus.

- *

Quercus is a PHP interpreter written in Java, distributed by Caucho. - * Quercus is embedded inside a Java EE compliant application server called Resin. Resin gives - * you the flexibility of writing PHP applications that have access to the Java ecosystem, and is - * many times more efficient than running PHP in Apache.

- *

If you're wanting to run large-scale PHP applications on Java, you need to take a look at Resin. - * But if you're just looking to make PHP libraries like GeSHi - * available to your Java and Groovy code, our PHP-in-Java library is for you.

- *

Using PHP-in-Java

- *

For usage instructions, please refer to README on our Github project.

- * @author Aaron Collegeman aaron@collegeman.net - */ -public class PHP { - - private static final Logger log = Logger.getLogger(PHP.class.getName()); - private static XLRQuercus xlrQuercus; - - private synchronized XLRQuercus getQuercus() { - if (xlrQuercus == null) { - xlrQuercus = new XLRQuercus(); - xlrQuercus.init(); - xlrQuercus.start(); - } - return xlrQuercus; - } - - /** - * Initialize a PHP wrapper with either an intial PHP script or a local directory. - *

url can take one of several forms:

- * - * @param url An initial PHP script to load or a local directory - */ - public PHP(String url, String logFileName, String ... args) throws Exception { - this(url, PHP.class.getClassLoader(), logFileName, args); - } - - private QuercusPage main; - - /** - * Create an empty instance of PHP. This instance can be used to execute arbitrary - * snippets of PHP. But if you're looking to load a PHP library and execute snippets against that, - * best to use one of the other constructors - */ - public PHP() {} - - - /** - * Initialize a PHP wrapper with a specific ClassLoader instance. Refer - * to the doc for for a description of the url parameter. - */ - public PHP(String url, ClassLoader classLoader, String logFileName, String ... args) throws Exception { - if (url == null || url.length() < 1) - throw new IllegalArgumentException("[url] parameter must be defined"); - - if (classLoader == null) - throw new IllegalArgumentException("[classLoader] parameter must be defined"); - - // classpath reference - if (url.indexOf("classpath:/") == 0) { - URL resource = classLoader.getResource(url.substring(11)); - File ref = new File(resource.getPath()); - initByFile(ref, logFileName, args); - } - - // remote script - else if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) { - try { - URLConnection conn = new URL(url).openConnection(); - initByInputStream(conn.getInputStream()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - // file reference - else { - initByFile(new File(url), logFileName, args); - } - - } - - /** - * Initialize a PHP wrapper with a specific File loaded by the host. - * @param file A file full of PHP script - */ - public PHP(File file, String logFileName, String ... args) throws Exception { - initByFile(file, logFileName, args); - } - - private void initByInputStream(InputStream stream) { - try { - StringBuilder sourceCode = new StringBuilder(1024); - BufferedReader in = new BufferedReader(new InputStreamReader(stream)); - char[] buffer = new char[1024]; - int read = 0; - while ((read = in.read(buffer)) != -1) - sourceCode.append(buffer, 0, read); - in.close(); - - snippet(sourceCode.toString()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private void initByFile(File ref, String logFileName, String ... args) throws Exception { - if (!ref.exists()) { - throw new RuntimeException(new FileNotFoundException("No PHP file or directory at ["+ref.getAbsolutePath()+"]")); - } - - if (ref.isDirectory()) { - snippet(""); - getEnv().setPwd(new FilePath(ref.getAbsolutePath())); - } - else { - File dir = ref.getParentFile(); - String [] arguments = ArrayUtils.addAll(new String [] {"-f", ref.getAbsolutePath(),logFileName}, args); - - getQuercus().processArguments(arguments); - - if (dir != null) { - try { - - QuercusPage page = getQuercus().parse(new FilePath(ref.getAbsolutePath())); - initEnv(page); - getEnv().setPwd(new FilePath(ref.getParentFile().getAbsolutePath())); - - getEnv().execute(); - } catch (QuercusDieException var11) { - log.log(Level.SEVERE, var11.getMessage(), var11); - throw var11; - } catch (QuercusExitException var12) { - log.log(Level.SEVERE, var12.getMessage(), var12); - throw var12; - } catch (QuercusErrorException var13) { - log.log(Level.SEVERE, var13.getMessage(), var13); - throw var13; - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - } - - } - } - - private Env env; - private WriteStream os = new WriteStream(StringBuilderStream.create()); - - private void initEnv(QuercusPage page) throws UnsupportedEncodingException { - if (env == null) { - os.setNewlineString("\n"); - os.setEncoding("iso-8859-1"); - - - env = getQuercus().createEnv(page, os, (QuercusHttpServletRequest)null, (QuercusHttpServletResponse)null); - - env.setPwd(new FilePath(System.getProperty("user.dir"))); - - env.start(); - } - } - - /** - * Retrieves the Quercus execution environment, which your Java code - * can use to interact directly with the Quercus parsing engine. - * @link http://www.caucho.com/resin-javadoc/com/caucho/quercus/env/Env.html - * @throws IllegalStateException When environment has not yet been initialized - */ - private Env getEnv() { - if (env == null) - throw new IllegalStateException("Environment not yet initialized"); - return env; - } - - /** - * Set the value of a global variable in the PHP execution environment. - * @param name The name of the global parameter to create/update - * @param obj The value to store there - */ - PHP set(String name, Object obj) { - snippet(""); - getEnv().setGlobalValue(name, toValue(getEnv(), obj)); - return this; - } - - /** - * Retrieve the value of a global varialbe in the PHP execution environment. - * @param name The name of the global parameter tto read - */ - PHPObject get(String name) { - snippet(""); - return new PHPObject(getEnv(), getEnv().getGlobalValue(name)); - } - - /** - * Ensures that obj is of type or wrapped in an instance - * of Quercus' Value, with respect to the given execution - * environment env. - * @return obj or obj wrapped in a Value instance. - */ - static Value toValue(Env env, Object obj) { - if (obj == null) - return env.wrapJava(obj); - else if (obj instanceof PHPObject) - return ((PHPObject) obj).getWrappedValue(); - else if (obj instanceof Value) - return (Value) obj; - else - return env.wrapJava(obj); - } - - /** - * Parse and execute a snippet of PHP script, adding to the - * execution context any artifacts and/or output generated by the code. - */ - PHP snippet(String snippet) { - try { - QuercusPage page = getQuercus().parse(StringStream.open(snippet)); - initEnv(page); - page.executeTop(getEnv()); - } catch (IOException e) { - throw new RuntimeException(e); - } - - return this; - } - - /** - * Retrieve the output generated by all PHP scripts executed in this context. - */ - public String toString() { - if (env != null) { - try { - os.flush(); - return os.getSource().toString(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - else { - return null; - } - } - - /** - * Call the PHP function named fxName with arguments args - * @return An instance of PHPObject, wrapped around the return value of the function. - */ - PHPObject fx(String fxName, Object... args) { - if (args != null && args.length > 0) { - Value[] values = new Value[args.length]; - for (int i=0; iclassName, initialized with - * arguments args. - * @return An instance of PHPObject, wrapping the new instance of className. - */ - PHPObject newInstance(String className, Object... args) { - QuercusClass clazz = getEnv().findClass(className); - if (clazz == null) - throw new RuntimeException(new ClassNotFoundException("PHP:"+className)); - - if (args != null && args.length > 0) { - Value[] values = new Value[args.length]; - for (int i=0; icom.caucho.quercus.env.Value, themselves representing - * instances of PHP objects. This wrapper makes it easier to invoke methods and set and get properties. - * @author Aaron Collegeman aaron@collegeman.net - */ -public class PHPObject { - - private Value wrapped; - - private Env env; - - public PHPObject(Env env, Value value) { - this.env = env; - this.wrapped = value; - } - - /** - * Invoke the method name on wrapped Value object, passing - * into the invocation parameters args. - * @return An instance of PHPObject, wrapping any return value of nameed method. - */ - public final PHPObject invokeMethod(String name, Object ... args) { - if (args != null && args.length > 0) { - Value values[] = new Value[args.length]; - for(int i=0; iValue to value. - * @return This instance of PHPObject, to support method chaining. - */ - public final PHPObject setProperty(String name, Object value) { - wrapped.putField(env, new StringBuilderValue(name), PHP.toValue(env, value)); - return this; - } - - /** - * Retrieve a public property name of the wrapped Value. - * @return A new instance of PHPObject, wrapping the retrieved property. - */ - public final PHPObject getProperty(String name) { - return new PHPObject(env, wrapped.getField(env, new StringBuilderValue(name))); - } - - public Value getWrappedValue() { - return wrapped; - } - - public String toString() { - return wrapped.toJavaString(); - } - -} \ No newline at end of file diff --git a/src/main/resources/ispw/ISPWClient.py b/src/main/resources/ispw/ISPWClient.py new file mode 100644 index 0000000..a7a639b --- /dev/null +++ b/src/main/resources/ispw/ISPWClient.py @@ -0,0 +1,73 @@ +# +# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS +# FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS. +# + +from ispwHttp.HttpRequest import HttpRequest + +import json, time + + +class ISPWClient(object): + def __init__(self, http_connection, username=None, password=None): + self.http_request = HttpRequest(http_connection, username, password) + + @staticmethod + def create_client(http_connection, username=None, password=None): + return ISPWClient(http_connection, username, password) + + def create_release(self, release_id, application, stream, release_description, user): + context_root = "/ispw/w3t/releases/%s/create?applid=%s&stream=%s&desc=%s&ownerid=%s" % (release_id, application, stream, release_description, user) + headers = {'Accept': 'application/json'} + response = self.http_request.put(context_root, None, headers=headers) + if not response.isSuccessful(): + raise Exception("Failed to create release [%s]. Server return [%s], with content [%s]" % (release_id, response.status, response.response)) + else: + print "Created release with id [%s]. Server return [%s], with content [%s]\n" % (release_id, response.status, response.response) + + def promote(self, release_id, level): + context_root = "/ispw/w3t/releases/%s/promote?level=%s" % (release_id, level) + headers = {'Accept': 'application/json'} + response = self.http_request.post(context_root, None, headers=headers) + if not response.isSuccessful(): + raise Exception("Failed to promote release [%s]. Server return [%s], with content [%s]" % (release_id, response.status, response.response)) + else: + print "Called promote release with id [%s]. Server return [%s], with content [%s]\n" % (release_id, response.status, response.response) + return json.loads(response.response)['statusUri'] + + def deploy(self, release_id, level): + context_root = "/ispw/w3t/releases/%s/deploy?level=%s" % (release_id, level) + headers = {'Accept': 'application/json'} + response = self.http_request.post(context_root, None, headers=headers) + if not response.isSuccessful(): + raise Exception("Failed to deploy release [%s]. Server return [%s], with content [%s]" % (release_id, response.status, response.response)) + else: + print "Called deploy release with id [%s]. Server return [%s], with content [%s]\n" % (release_id, response.status, response.response) + return json.loads(response.response)['statusUri'] + + def check_status(self, status_uri, number_of_polling_trials, polling_interval): + trial = 0 + while not number_of_polling_trials or trial < number_of_polling_trials: + trial += 1 + result = self.get_status(status_uri) + if result == "C": + print "Deployment completed.\n" + return + if result == "F": + print "Deployment failed.\n" + raise Exception("Failed to deploy release [%s]." % status_uri) + print "Will try again in [%d] seconds.\n" % polling_interval + time.sleep(polling_interval) + raise Exception("Status checked timed out.\n") + + + def get_status(self, status_uri): + headers = {'Accept': 'application/json'} + self.http_request.params.url = status_uri + response = self.http_request.get('', headers=headers) + if not response.isSuccessful(): + raise Exception("Failed to get status for uri [%s]. Server return [%s], with content [%s]" % (status_uri, response.status, response.response)) + else: + print "Received status for uri [%s]. Server return [%s], with content [%s]\n" % (status_uri, response.status, response.response) + return json.loads(response.response)['set']['execstat'] diff --git a/src/main/resources/ispw/ISPWClientUtil.py b/src/main/resources/ispw/ISPWClientUtil.py new file mode 100644 index 0000000..c19092f --- /dev/null +++ b/src/main/resources/ispw/ISPWClientUtil.py @@ -0,0 +1,14 @@ +# +# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS +# FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS. +# + +from ispw.ISPWClient import ISPWClient + + +class ISPWClientUtil(object): + + @staticmethod + def create_ispw_client(container, username, password): + return ISPWClient.create_client(container, username, password) \ No newline at end of file diff --git a/src/main/resources/ispw/__init__.py b/src/main/resources/ispw/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/ispw/createRelease.py b/src/main/resources/ispw/createRelease.py new file mode 100644 index 0000000..e1334b3 --- /dev/null +++ b/src/main/resources/ispw/createRelease.py @@ -0,0 +1,5 @@ +from ispw.ISPWClientUtil import ISPWClientUtil + +ispw_client = ISPWClientUtil.create_ispw_client(ispwServiceServer, username, password) + +ispw_client.create_release(release_id=relid, application=application, stream=stream, release_description=description, user=user) \ No newline at end of file diff --git a/src/main/resources/ispw/deploy.py b/src/main/resources/ispw/deploy.py new file mode 100644 index 0000000..bad460d --- /dev/null +++ b/src/main/resources/ispw/deploy.py @@ -0,0 +1,6 @@ +from ispw.ISPWClientUtil import ISPWClientUtil + +ispw_client = ISPWClientUtil.create_ispw_client(ispwServiceServer, username, password) + +status_uri = ispw_client.deploy(relid, level) +ispw_client.check_status(status_uri, numberOfPollingTrials, pollingInterval) diff --git a/src/main/resources/ispw/promote.py b/src/main/resources/ispw/promote.py new file mode 100644 index 0000000..9be86c3 --- /dev/null +++ b/src/main/resources/ispw/promote.py @@ -0,0 +1,6 @@ +from ispw.ISPWClientUtil import ISPWClientUtil + +ispw_client = ISPWClientUtil.create_ispw_client(ispwServiceServer, username, password) + +status_uri = ispw_client.promote(relid, level) +ispw_client.check_status(status_uri, numberOfPollingTrials, pollingInterval) \ No newline at end of file diff --git a/src/main/resources/ispwHttp/HttpRequest.py b/src/main/resources/ispwHttp/HttpRequest.py new file mode 100644 index 0000000..e946d99 --- /dev/null +++ b/src/main/resources/ispwHttp/HttpRequest.py @@ -0,0 +1,217 @@ +import re +import urllib + +from java.lang import String + +from org.apache.commons.codec.binary import Base64 +from org.apache.http import HttpHost +from org.apache.http.client.config import RequestConfig +from org.apache.http.client.methods import HttpGet, HttpPost, HttpPut, HttpDelete, HttpPatch +from org.apache.http.util import EntityUtils +from org.apache.http.entity import StringEntity +from org.apache.http.impl.client import HttpClients + +from com.xebialabs.xlrelease.domain.configuration import HttpConnection +from xlrelease.HttpResponse import HttpResponse + + +class HttpRequest: + def __init__(self, params, username = None, password = None): + """ + Builds an HttpRequest + + :param params: an HttpConnection + :param username: the username + (optional, it will override the credentials defined on the HttpConnection object) + :param password: an password + (optional, it will override the credentials defined on the HttpConnection object) + """ + self.params = HttpConnection(params) + self.username = username + self.password = password + + def doRequest(self, **options): + """ + Performs an HTTP Request + + :param options: A keyword arguments object with the following properties : + method: the HTTP method : 'GET', 'PUT', 'POST', 'DELETE', 'PATCH' + (optional: GET will be used if empty) + context: the context url + (optional: the url on HttpConnection will be used if empty) + body: the body of the HTTP request for PUT & POST calls + (optional: an empty body will be used if empty) + contentType: the content type to use + (optional, no content type will be used if empty) + headers: a dictionary of headers key/values + (optional, no headers will be used if empty) + :return: an HttpResponse instance + """ + request = self.buildRequest( + options.get('method', 'GET'), + options.get('context', ''), + options.get('body', ''), + options.get('contentType', None), + options.get('headers', None)) + return self.executeRequest(request) + + + def get(self, context, **options): + """ + Performs an HTTP GET Request + + :param context: the context url + :param options: the options keyword argument described in doRequest() + :return: an HttpResponse instance + """ + options['method'] = 'GET' + options['context'] = context + return self.doRequest(**options) + + + def put(self, context, body, **options): + """ + Performs an HTTP PUT Request + + :param context: the context url + :param body: the body of the HTTP request + :param options: the options keyword argument described in doRequest() + :return: an HttpResponse instance + """ + options['method'] = 'PUT' + options['context'] = context + options['body'] = body + return self.doRequest(**options) + + + def post(self, context, body, **options): + """ + Performs an HTTP POST Request + + :param context: the context url + :param body: the body of the HTTP request + :param options: the options keyword argument described in doRequest() + :return: an HttpResponse instance + """ + options['method'] = 'POST' + options['context'] = context + options['body'] = body + return self.doRequest(**options) + + + def delete(self, context, **options): + """ + Performs an HTTP DELETE Request + + :param context: the context url + :param options: the options keyword argument described in doRequest() + :return: an HttpResponse instance + """ + options['method'] = 'DELETE' + options['context'] = context + return self.doRequest(**options) + + def patch(self, context, body, **options): + """ + Performs an HTTP PATCH Request + + :param context: the context url + :param body: the body of the HTTP request + :param options: the options keyword argument described in doRequest() + :return: an HttpResponse instance + """ + options['method'] = 'PATCH' + options['context'] = context + options['body'] = body + return self.doRequest(**options) + + def buildRequest(self, method, context, body, contentType, headers): + url = self.quote(self.createPath(self.params.getUrl(), context)) + + method = method.upper() + + if method == 'GET': + request = HttpGet(url) + elif method == 'POST': + request = HttpPost(url) + if body: + request.setEntity(StringEntity(body)) + elif method == 'PUT': + request = HttpPut(url) + if body: + request.setEntity(StringEntity(body)) + elif method == 'DELETE': + request = HttpDelete(url) + elif method == 'PATCH': + request = HttpPatch(url) + request.setEntity(StringEntity(body)) + else: + raise Exception('Unsupported method: ' + method) + + self.setCredentials(request) + self.setProxy(request) + self.setHeaders(request, headers) + + return request + + + def createPath(self, url, context): + url = re.sub('/*$', '', url) + if context is None: + return url + elif context.startswith('/'): + return url + context + else: + return url + '/' + context + + def quote(self, url): + return urllib.quote(url, ':/?&=%') + + + def setCredentials(self, request): + if self.username: + username = self.username + password = self.password + elif self.params.getUsername(): + username = self.params.getUsername() + password = self.params.getPassword() + else: + return + + encoding = Base64.encodeBase64String(String(username + ':' + password).getBytes('ISO-8859-1')) + request.addHeader('Authorization', 'Basic ' + encoding) + + + def setProxy(self, request): + if not self.params.getProxyHost(): + return + + proxy = HttpHost(self.params.getProxyHost(), int(self.params.getProxyPort())) + config = RequestConfig.custom().setProxy(proxy).build() + request.setConfig(config) + + + def setHeaders(self, request, headers): + if headers: + for key in headers: + request.setHeader(key, headers[key]) + + + def executeRequest(self, request): + client = None + response = None + try: + client = HttpClients.createDefault() + response = client.execute(request) + status = response.getStatusLine().getStatusCode() + entity = response.getEntity() + result = EntityUtils.toString(entity, "UTF-8") if entity else None + headers = response.getAllHeaders() + EntityUtils.consume(entity) + + return HttpResponse(status, result, headers) + finally: + if response: + response.close() + if client: + client.close() \ No newline at end of file diff --git a/src/main/resources/ispwHttp/__init__.py b/src/main/resources/ispwHttp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/synthetic.xml b/src/main/resources/synthetic.xml index d4b5728..44fb737 100644 --- a/src/main/resources/synthetic.xml +++ b/src/main/resources/synthetic.xml @@ -8,57 +8,51 @@ --> - - \ No newline at end of file diff --git a/src/main/resources/web/include/ISPWTile/js/ispw-tile.js b/src/main/resources/web/include/ISPWTile/js/ispw-tile.js index d6c39e0..66d0810 100644 --- a/src/main/resources/web/include/ISPWTile/js/ispw-tile.js +++ b/src/main/resources/web/include/ISPWTile/js/ispw-tile.js @@ -34,7 +34,7 @@ function getAllISPWTasks(release) { return _(ReleasesService.getLeafTasks(release)) - .filter({scriptDefinitionType: "ispw." + vm.config.action}) + .filter({scriptDefinitionType: "ispwServices." + vm.config.action}) .map(function (task) { return { taskName: task.title, diff --git a/src/main/resources/xlrelease/phpRequest.py b/src/main/resources/xlrelease/phpRequest.py deleted file mode 100644 index dd218f8..0000000 --- a/src/main/resources/xlrelease/phpRequest.py +++ /dev/null @@ -1,21 +0,0 @@ - -from java.io import File -from net.collegeman.phpinjava import PHP -from org.apache.commons.io import FileUtils - - -arguments = [] -props = getCurrentTask().getPythonScript().getInputProperties() - -for k in props: - arguments.append("%s=%s" % (k.name,getCurrentTask().getPythonScript().getProperty(k.name))) - -php = None -try: - php = PHP(File("%s/%s" % (phpHomeFolder,phpScript)), logFileName, arguments) -except: - log_output = FileUtils.readFileToString(File("%s/%s.log" % (phpHomeFolder,logFileName))) - print "The log file contains: %s" % log_output -finally: - output = php.toString() - print "We received the following through php [%s]" % output \ No newline at end of file