Skip to content

Commit

Permalink
Merge pull request #5 from inkysea/master
Browse files Browse the repository at this point in the history
Merge for bug fix JENKINS-34015
  • Loading branch information
inkysea committed Apr 6, 2016
2 parents b814c11 + 3e86aa0 commit ff2a6a6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 23 deletions.
46 changes: 40 additions & 6 deletions README.md
Expand Up @@ -40,15 +40,49 @@ Configure : Configure the plugin as shown
* Password - Password for user
* Blueprint - The name of the blueprint to be provisioned.
* Execute and Wait - If checked the Jenkins job will wait for the blueprint to be provisioned
* Request using Blueprint Template - Disabled by default. Checking this box will use the blueprint template. I've
disabled this as requesting via Blueprint Template's provide inconsistent results if you have multiple network profiles
defined in your reservation. Also note that using the blueprint template means that the JSON required for the deployment
configuration options will differ.
* Add Deployment Configuration - Deployment configuration parameters can be specified to adjust settings such as CPU.
Parameters are specified as JSON.

Parameters are specified as JSON. Thy format of the JSON string will differ if you have the "Request using
Blueprint Template" enabled.

![Configure](/doc/vRA_BuildStep.png)


## Deployment Parameters

The format of your configuration JSON will depend on your selection of the "Request using Blueprint Template" option.
If you stay with the default, option is unchecked, you will define the JSON like the string below. Note: Due to format
constraints, I had to place white space to allow for bold. Please exclude the white space.

{"key":"provider- **CommerceWebApp_1** ",
"value":{"type":"complex",
"values":{" *entries* " :[
{"key":" **artifactURL** ", "value":{"type":"string", "value":" **http://artifactserver/commerceApp.zip** "}}
]
}
}
}

The JSON for parameters can be determined by looking at the JSON blueprint template from vRA. The template for a
blueprint can be viewed by running a build job and looking at the console output or using the vRealize cloudclient.
See below for the JSON blueprint logged to the build console.
Note the bold text will change based on your blueprint. The provider name will be the name of your component in the
blueprint. The entries array in the JSON will be a key/value mapping. In this case my key is artifactURL, which is
also the property in my blueprint that I want to set a value. The value is set to my artifact repository URL. Since this is
a JSON array, you can specify multiple key/value pairs that belong to same provider.

for example: "entries": [ { "key":"var1", "value"="value1" } , { "key":"var2", "value"="value2" } ]


If you choose "Request using Blueprint Template" then your JSON format must match the blueprint templates contents.
The blueprint template will be logged to the console window as shown below. You may also get the template using the
cloudclient. Simply search for the section that contains the parameter you wish to change and copy that JSON to your
deployment configuration paramemters. I'd recommend using a friendly JSON editor to look at the contents of the blueprint
template so that you can select the parameters you wish to modify.

For example: A simple CPU change in a blueprint template where CentOS7 is the name of the VM in the blueprint.

{"data":{" **CentOS7** ":{"data":"cpu":2}}}}

![Configure](/doc/console.png)

Expand Down
Binary file modified doc/BuildJob.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/vRA_BuildStep.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -81,7 +81,7 @@ public boolean Create() throws IOException, InterruptedException {
JsonParser parser = new JsonParser();

for ( RequestParam option : params.getRequestParams()){
if (option.getJson().isEmpty() ){
if ( option.getJson() == null ){

logger.println("Request Parameter is null. skipping to next parameter");

Expand Down Expand Up @@ -202,8 +202,16 @@ private JsonObject requestCreateJSON(){
entriesArray.add(entries);

for ( RequestParam option : params.getRequestParams()) {
JsonElement response = new JsonParser().parse(option.getJson()).getAsJsonObject();
entriesArray.add( response );

if ( option.getJson() == null ){

logger.println("Request Parameter is null. skipping to next parameter");

}else {
logger.println("Request Parameter : " + option.getJson());
JsonElement response = new JsonParser().parse(option.getJson()).getAsJsonObject();
entriesArray.add(response);
}

}

Expand Down
Expand Up @@ -61,7 +61,8 @@ public Request(PrintStream logger, PluginParam params) throws IOException {
e.printStackTrace();
}

String catalogServiceApiUrl = params.getServerUrl() + "/catalog-service/api/";
String catalogServiceApiUrl = params.getServerUrl().replaceFirst("/+$", "")
+ "/catalog-service/api/";

this.REQUESTS_ID_URL = catalogServiceApiUrl + "consumer/requests/%s";
this.REQUESTS_POST_URL = catalogServiceApiUrl + "consumer/requests/";
Expand Down Expand Up @@ -98,7 +99,7 @@ public Request(PrintStream logger, DestroyParam dparams) throws IOException {
e.printStackTrace();
}

String catalogServiceApiUrl = dparams.getServerUrl() + "/catalog-service/api/";
String catalogServiceApiUrl = dparams.getServerUrl().replaceFirst("/+$", "") + "/catalog-service/api/";

this.REQUESTS_ID_URL = catalogServiceApiUrl + "consumer/requests/%s";
this.REQUESTS_POST_URL = catalogServiceApiUrl + "consumer/requests/";
Expand All @@ -113,6 +114,7 @@ public Request(PrintStream logger, DestroyParam dparams) throws IOException {
}

public Request(PrintStream logger, String vRA_URL, String userName, String password, String tenant ) {
// Constructor for blueprint requests

this.logger = logger;

Expand All @@ -124,7 +126,7 @@ public Request(PrintStream logger, String vRA_URL, String userName, String passw
e.printStackTrace();
}

String catalogServiceApiUrl = vRA_URL + "/catalog-service/api/";
String catalogServiceApiUrl = vRA_URL.replaceFirst("/+$", "") + "/catalog-service/api/";

this.REQUESTS_ID_URL = catalogServiceApiUrl + "consumer/requests/%s";
this.REQUESTS_POST_URL = catalogServiceApiUrl + "consumer/requests/";
Expand Down Expand Up @@ -209,6 +211,8 @@ public JsonObject Packages(String file, String resolutionMode) throws IOExceptio

public JsonObject fetchBluePrint() throws IOException {
JsonObject response = null;
System.out.println("Fetching BP :" + params.getBluePrintName());

String url = String.format(FETCH_CATALOG_ITEM, params.getBluePrintName()).replace(' ', '+');
System.out.println("Using :" + url);

Expand Down Expand Up @@ -246,14 +250,19 @@ public JsonObject GetBluePrintTemplate() throws IOException {

JsonObject response = this.fetchBluePrint();

String catalogId = response.getAsJsonObject().getAsJsonPrimitive("catalogItemId").toString();
this.catalogId = catalogId.replaceAll("^\"|\"$", "");
JsonArray catalogItemContentArray = response.getAsJsonArray("content");

this.catalogId = catalogItemContentArray.get(0).getAsJsonObject()
.get("catalogItemId").getAsString();

JsonArray linkArray = catalogItemContentArray.get(0)
.getAsJsonObject()
.getAsJsonArray("links");

JsonArray linkArray = response.getAsJsonArray("links");
System.out.println("Links Array: "+linkArray);


String templateURL = linkArray.get(0).getAsJsonObject().get("href").toString();
templateURL = templateURL.replaceAll("^\"|\"$", "");
String templateURL = linkArray.get(0).getAsJsonObject().get("href").getAsString();

String url = templateURL;
System.out.println("Get BP Template: "+templateURL);
Expand Down
Expand Up @@ -37,9 +37,9 @@ public Boolean validate() throws IOException {
throw new IOException("Deployment Parameter can not be empty");
}


return true;
}

public String getJson() {
return json;
}
Expand Down
Expand Up @@ -80,13 +80,18 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
int counter = 1;
for (PluginParam param : params) {

// Resolve any build variables included in the request paramaters.

// Resolve any build variables included in the request paramaters.
List<RequestParam> rparamResolved = new ArrayList<RequestParam>();;

for(RequestParam rparam : param.getRequestParams()){
String rparamString = helper.replaceBuildParamWithValue(rparam.getRequestParam().toString());
rparamResolved.add(new RequestParam(rparamString));
}
if ( ! (null == param.getRequestParams()) || param.getRequestParams().isEmpty()) {


for (RequestParam rparam : param.getRequestParams()) {
String rparamString = helper.replaceBuildParamWithValue(rparam.getRequestParam().toString());
rparamResolved.add(new RequestParam(rparamString));
}
}

// Resolve any environment variables in the parameters
PluginParam fparam = new PluginParam(helper.replaceBuildParamWithValue(param.getServerUrl()),
Expand Down

0 comments on commit ff2a6a6

Please sign in to comment.