Skip to content

Commit

Permalink
PC Adding features (#194)
Browse files Browse the repository at this point in the history
* index on master: ab83a3d Merge remote-tracking branch 'remotes/origin/5.0.1-beta-SNAPSHOT'

* Revert pom changes

* Merge branch '5.0.1-beta-SNAPSHOT' of https://github.com/hpsa/hp-application-automation-tools-plugin into development

# Conflicts:
#	.github/PULL_REQUEST_TEMPLATE.md

* Added some comments

* changes according to sonarlint

* changes for sonarlint

* Remove some comments

* Comments

*  * Fix for supporting SECURITY-170 changes
 * https://jenkins.io/blog/2016/05/11/security-update/
 * https://issues.jenkins-ci.org/browse/JENKINS-39654

* code changes for sonarlint

* Changes in PC configuration section header

* Adding support for Jenkins using proxy:  https://issues.jenkins-ci.org/browse/JENKINS-44314
Changing the HTTPS checkbox position

* Adding link under Test ID text box for browsing to the PC Server
  • Loading branch information
bamh authored and YafimK committed May 21, 2017
1 parent e1c13c6 commit e86d97d
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 76 deletions.
Expand Up @@ -28,11 +28,12 @@ public class PcModel {
private final boolean addRunToTrendReport;
private final String trendReportId;
private final boolean HTTPSProtocol;
private final String proxyOutURL;

@DataBoundConstructor
public PcModel(String pcServerName, String almUserName, String almPassword, String almDomain, String almProject,
String testId, String testInstanceId, String timeslotDurationHours, String timeslotDurationMinutes,
PostRunAction postRunAction, boolean vudsMode, String description, boolean addRunToTrendReport, String trendReportId, boolean HTTPSProtocol) {
PostRunAction postRunAction, boolean vudsMode, String description, boolean addRunToTrendReport, String trendReportId, boolean HTTPSProtocol, String proxyOutURL) {

this.pcServerName = pcServerName;
this.almUserName = almUserName;
Expand All @@ -48,6 +49,7 @@ public PcModel(String pcServerName, String almUserName, String almPassword, Stri
this.addRunToTrendReport = addRunToTrendReport;
this.HTTPSProtocol = HTTPSProtocol;
this.trendReportId = trendReportId;
this.proxyOutURL = proxyOutURL;
}

protected SecretContainer setPassword(String almPassword) {
Expand Down Expand Up @@ -116,6 +118,10 @@ public boolean httpsProtocol(){
return this.HTTPSProtocol;
}

public String getProxyOutURL(){
return this.proxyOutURL;
}


public static List<PostRunAction> getPostRunActions() {
return Arrays.asList(PostRunAction.values());
Expand Down
Expand Up @@ -54,9 +54,14 @@ public class PcClient {
private PrintStream logger;

public PcClient(PcModel pcModel, PrintStream logger) {
model = pcModel;
restProxy = new PcRestProxy(model.isHTTPSProtocol(),model.getPcServerName(), model.getAlmDomain(), model.getAlmProject(),logger);
this.logger = logger;
try {
model = pcModel;
restProxy = new PcRestProxy(model.isHTTPSProtocol(),model.getPcServerName(), model.getAlmDomain(), model.getAlmProject(),logger, model.getProxyOutURL());
this.logger = logger;
}catch (PcException e){
logger.println(e.getMessage());
}

}

public <T extends PcRestProxy> PcClient(PcModel pcModel, PrintStream logger, T proxy) {
Expand Down
Expand Up @@ -30,8 +30,8 @@
import com.hp.application.automation.tools.rest.RESTConstants;
import com.hp.application.automation.tools.sse.sdk.Base64Encoder;
import org.apache.commons.io.IOUtils;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
Expand All @@ -40,6 +40,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCookieStore;
Expand All @@ -53,9 +54,7 @@
import java.io.InputStream;
import java.io.IOException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;

import java.io.PrintStream;

Expand Down Expand Up @@ -84,13 +83,16 @@ public class PcRestProxy {
private String domain;
private String project;
private String webProtocol;
private String proxyScheme;
private String proxyHostName;
private int proxyPort;

private HttpClient client;
private HttpContext context;
private CookieStore cookieStore;
// private PrintStream logger;

public PcRestProxy(String webProtocolName, String pcServerName, String almDomain, String almProject,PrintStream mainLogger) {
public PcRestProxy(String webProtocolName, String pcServerName, String almDomain, String almProject,PrintStream mainLogger, String proxyOutURL) throws PcException {

// logger = mainLogger;
pcServer = pcServerName;
Expand All @@ -104,12 +106,42 @@ public PcRestProxy(String webProtocolName, String pcServerName, String almDomain
cxMgr.setDefaultMaxPerRoute(20);


client = new DefaultHttpClient(cxMgr);
client = new DefaultHttpClient(cxMgr);
if (proxyOutURL != null && !proxyOutURL.isEmpty()) {
// Setting proxy
// we should get the full proxy URL from the user: http(s)://<server>:<port>
// PAC (proxy auto-config) or Automatic configuration script is not supported (for example our proxy: http://autocache.hpecorp.net/)
getProxyDataFromURL(proxyOutURL);
HttpHost proxy = new HttpHost(proxyHostName, proxyPort, proxyScheme);
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
context = new BasicHttpContext();
cookieStore = new BasicCookieStore();
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}

private void getProxyDataFromURL(String proxyURL) throws PcException{

try {
if (proxyURL != null && !proxyURL.isEmpty()){
proxyScheme = proxyURL.split("://")[0];
proxyHostName = proxyURL.split("://")[1].split(":")[0];
if (proxyURL.split("://")[1].contains(":")){
proxyPort = Integer.parseInt(proxyURL.split("://")[1].split(":")[1]);
}else{
proxyPort = 80;
}

}
} catch (Exception ex) {
throw new PcException("Error: Validating Proxy URL: " + ex + " Please add a proxy URL in this pattern: http(s)://<host>:<port> or leave blank");
}




}


public boolean authenticate(String userName, String password) throws PcException, ClientProtocolException, IOException {
String userNameAndPassword = userName + ":" + password;
Expand Down Expand Up @@ -222,14 +254,7 @@ public boolean logout() throws PcException, ClientProtocolException, IOException
}

protected HttpResponse executeRequest(HttpRequestBase request) throws PcException, IOException {
// logger.println(String.format("DEBUGMSG - Request uri %s",request.getURI().toString()));
// logger.println(String.format("DEBUGMSG - Request Method %s",request.getMethod().toString()));
// // Print all headers
// logger.println("DEBUGMSG - Headers");
// List<Header> httpHeaders = Arrays.asList(request.getAllHeaders());
// for (Header header : httpHeaders) {
// logger.println("DEBUGMSG - " + header.getName() + " : " + header.getValue());
// }

HttpResponse response = client.execute(request,context);
if (!isOk(response)){
String message;
Expand Down
Expand Up @@ -110,7 +110,8 @@ public PcBuilder(
String description,
boolean addRunToTrendReport,
String trendReportId,
boolean HTTPSProtocol) {
boolean HTTPSProtocol,
String proxyOutURL) {
this.almUserName = almUserName;
this.almPassword = almPassword;
this.timeslotDurationHours = timeslotDurationHours;
Expand All @@ -133,7 +134,8 @@ public PcBuilder(
description,
addRunToTrendReport,
trendReportId,
HTTPSProtocol);
HTTPSProtocol,
proxyOutURL);
}

@Override
Expand Down Expand Up @@ -625,6 +627,8 @@ public boolean isStatusBySLA() {
return statusBySLA;
}

public String getProxyOutURL(){ return getPcModel().getProxyOutURL();}

// This indicates to Jenkins that this is an implementation of an extension
// point
@Extension
Expand All @@ -646,7 +650,7 @@ public boolean isApplicable(
@Override
public String getDisplayName() {

return "Execute HP tests using HP Performance Center";
return "Execute performance test using Performance Center";
}

public FormValidation doCheckPcServerName(@QueryParameter String value) {
Expand Down
Expand Up @@ -59,6 +59,22 @@

}

function verifyURLAvailable(){

var pcServer = document.getElementsByName("pc.pcServerName")[0].value;
var scheme = "http";
if(document.getElementsByName("pc.HTTPSProtocol")[0].checked){
scheme = "https"
}
if(pcServer){
var popup = window.open(scheme + "://" + pcServer + "/loadtest/");
popup.opener = null;
}else{
alert("Performance Center Server name is missing.");
}
return false;
}

</script>
</f:block>

Expand All @@ -75,8 +91,9 @@
<f:textbox name="pc.description" value="${instance.pcModel.description}" />
</f:entry>
<f:entry title="PC Server" field="pcServerName">
<f:textbox name="pc.pcServerName" value="${instance.pcModel.pcServerName}" />
<f:textbox name="pc.pcServerName" value="${instance.pcModel.pcServerName}" onchange="verifyURLAvailable" />
</f:entry>
<f:optionalBlock title="Use HTTPS Protocol" field="HTTPSProtocol" name="pc.HTTPSProtocol" checked="${instance.pcModel.HTTPSProtocol}" />
<f:entry title="User name" field="almUserName">
<f:textbox name="pc.almUserName" value="${instance.pcModel.almUserName}" />
</f:entry>
Expand All @@ -92,9 +109,15 @@
<f:entry title="Test ID" field="testId">
<f:textbox name="pc.testId" value="${instance.pcModel.testId}" />
</f:entry>
<f:entry title="&#160;&#160;&#160;&#160;&#160;" field="">
<a id="pcServerURL" href="#" onclick="verifyURLAvailable();return false;">Browse to find the Test ID</a>
</f:entry>
<f:entry title="Test Instance ID &#160;" field="testInstanceId">
<f:textbox name="pc.testInstanceId" value="${instance.pcModel.testInstanceId}" />
</f:entry>
<f:entry title="Local Proxy" field="proxyOutURL">
<f:textbox name="pc.proxyOutURL" value="${instance.pcModel.proxyOutURL}" />
</f:entry>
<f:block>
<br />
</f:block>
Expand Down Expand Up @@ -205,7 +228,7 @@
<br />
</f:block>

<f:optionalBlock title="Use HTTPS Protocol" field="HTTPSProtocol" name="pc.HTTPSProtocol" checked="${instance.pcModel.HTTPSProtocol}" inline="true" />

<f:block>
<br />
</f:block>
Expand Down
@@ -0,0 +1,5 @@
<div>
Add your local proxy as following: <b>http(s)://&#60;host&#62;:&#60;port&#62;</b><br>
Leave empty if not using a local proxy.<br>
PAC (proxy auto-config) or Automatic configuration script are not supported.
</div>
@@ -1,19 +1,3 @@
/*
* Copyright 2017 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.hp.application.automation.tools.pc;

import com.hp.application.automation.tools.model.PcModel;
Expand All @@ -28,7 +12,7 @@ public MockPcModel(String pcServerName, String almUserName, String almPassword,
String almProject, String testId, String testInstanceId, String timeslotDurationHours,
String timeslotDurationMinutes, PostRunAction postRunAction, boolean vudsMode, String description,boolean webProtocol) {
super(pcServerName, almUserName, almPassword, almDomain, almProject, testId, testInstanceId, timeslotDurationHours,
timeslotDurationMinutes, postRunAction, vudsMode, description, false, null,false
timeslotDurationMinutes, postRunAction, vudsMode, description, false, null,false,null
);
}

Expand Down
@@ -1,19 +1,3 @@
/*
* Copyright 2017 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.hp.application.automation.tools.pc;

import java.io.File;
Expand Down Expand Up @@ -42,8 +26,8 @@ public class MockPcRestProxy extends PcRestProxy {

private static Iterator<RunState> runState = initializeRunStateIterator();

public MockPcRestProxy(String webProtocol, String pcServerName, String almDomain, String almProject,PrintStream logger) {
super(webProtocol, pcServerName, almDomain, almProject,logger);
public MockPcRestProxy(String webProtocol, String pcServerName, String almDomain, String almProject,PrintStream logger) throws PcException {
super(webProtocol, pcServerName, almDomain, almProject,logger,null);
}

@Override
Expand Down
@@ -1,19 +1,3 @@
/*
* Copyright 2017 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.hp.application.automation.tools.pc;

import java.io.IOException;
Expand All @@ -37,8 +21,8 @@ public class MockPcRestProxyBadResponses extends PcRestProxy {

private static Iterator<RunState> runState = initializeRunStateIterator();

public MockPcRestProxyBadResponses(String webProtocol, String pcServerName, String almDomain, String almProject,PrintStream logger) {
super(webProtocol, pcServerName, almDomain, almProject,logger);
public MockPcRestProxyBadResponses(String webProtocol, String pcServerName, String almDomain, String almProject,PrintStream logger) throws PcException {
super(webProtocol, pcServerName, almDomain, almProject,logger,null);
}

@Override
Expand Down

0 comments on commit e86d97d

Please sign in to comment.