Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldanan committed Feb 8, 2018
1 parent 2a25f05 commit 5c3db55
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 42 deletions.
105 changes: 77 additions & 28 deletions src/main/java/com/hpe/application/automation/tools/model/PcModel.java
Expand Up @@ -46,14 +46,15 @@ public class PcModel {
public static final String COLLATE = "Collate Results";
public static final String COLLATE_ANALYZE = "Collate and Analyze";
public static final String DO_NOTHING = "Do Not Collate";
private static final String EXPECTED_ALMPASSWORD_PARAMETER_NAME = "PCPASSWORD";

private final String serverAndPort;
private String pcServerName;
private String almUserName;
private SecretContainer almPassword;
private String almDomain;
private String almProject;
private String testId;
private final String pcServerName;
private final String almUserName;
private final SecretContainer almPassword;
private final String almDomain;
private final String almProject;
private final String testId;
private String testInstanceId;
private final String autoTestInstanceID;
private final TimeslotDuration timeslotDuration;
Expand All @@ -66,12 +67,13 @@ public class PcModel {
private final String proxyOutURL;
private final String proxyOutUser;
private final String proxyOutPassword;
private String buildParameters;


@DataBoundConstructor
public PcModel(String serverAndPort, String pcServerName, String almUserName, String almPassword, String almDomain, String almProject,
String testId,String autoTestInstanceID, String testInstanceId, String timeslotDurationHours, String timeslotDurationMinutes,
PostRunAction postRunAction, boolean vudsMode, String description, String addRunToTrendReport, String trendReportId, boolean HTTPSProtocol, String proxyOutURL, String proxyOutUser, String proxyOutPassword/*, String buildParameters*/) {
PostRunAction postRunAction, boolean vudsMode, String description, String addRunToTrendReport, String trendReportId, boolean HTTPSProtocol, String proxyOutURL, String proxyOutUser, String proxyOutPassword) {

this.serverAndPort = serverAndPort;
this.pcServerName = pcServerName;
Expand All @@ -92,6 +94,7 @@ public PcModel(String serverAndPort, String pcServerName, String almUserName, St
this.proxyOutURL = proxyOutURL;
this.proxyOutUser = proxyOutUser;
this.proxyOutPassword = proxyOutPassword;
this.buildParameters="";

}

Expand All @@ -111,35 +114,71 @@ public String getPcServerName() {
return this.pcServerName;
}

public String getPcServerName(boolean fromPcClient) {

return fromPcClient?useParameterIfNeeded(buildParameters,this.pcServerName):getPcServerName();
}

public String getAlmUserName() {

return this.almUserName;
}

public String getAlmUserName(boolean fromPcClient) {

return fromPcClient?useParameterIfNeeded(buildParameters,this.almUserName):getAlmUserName();
}

public SecretContainer getAlmPassword() {

return this.almPassword;
}

public SecretContainer getAlmPassword(boolean fromPcClient) {

return fromPcClient?useParameterForAlmPasswordIfNeeded(buildParameters,this.almPassword, EXPECTED_ALMPASSWORD_PARAMETER_NAME):getAlmPassword();
}

public String getAlmDomain() {

return this.almDomain;
}

public String getAlmDomain(boolean fromPcClient) {

return fromPcClient?useParameterIfNeeded(buildParameters,this.almDomain):getAlmDomain();
}

public String getAlmProject() {

return this.almProject;
}

public String getAlmProject(boolean fromPcClient) {

return fromPcClient?useParameterIfNeeded(buildParameters,this.almProject):getAlmProject();
}

public String getTestId() {

return this.testId;
}

public String getTestId(boolean fromPcClient) {

return fromPcClient?useParameterIfNeeded(buildParameters,this.testId):getTestId();
}

public String getTestInstanceId() {

return this.testInstanceId;
}

public String getTestInstanceId(boolean fromPcClient) {

return fromPcClient?useParameterIfNeeded(buildParameters,this.testInstanceId):getTestInstanceId();
}

public String getAutoTestInstanceID(){
return this.autoTestInstanceID;
}
Expand Down Expand Up @@ -172,42 +211,64 @@ public String getProxyOutURL(){
return this.proxyOutURL;
}

public String getProxyOutURL(boolean fromPcClient){
return fromPcClient?useParameterIfNeeded(buildParameters,this.proxyOutURL):getProxyOutURL();
}

public String getProxyOutUser(){
return this.proxyOutUser;
}

public String getProxyOutUser(boolean fromPcClient){
return fromPcClient?useParameterIfNeeded(buildParameters,this.proxyOutUser):getProxyOutUser();
}

public String getProxyOutPassword(){
return this.proxyOutPassword;
}

public String getProxyOutPassword(boolean fromPcClient){
return fromPcClient?useParameterIfNeeded(buildParameters,this.proxyOutPassword):getProxyOutPassword();
}

public static List<PostRunAction> getPostRunActions() {
return Arrays.asList(PostRunAction.values());
}

public String getBuildParameters() {
return this.buildParameters;
}


@Override
public String toString() {

return String.format("[PCServer='%s', User='%s', %s", runParamsToString().substring(1));
return String.format("%s", runParamsToString().substring(1));
}

public String runParamsToString() {

String vudsModeString = (vudsMode) ? ", VUDsMode='true'" : "";
String vudsModeString = (vudsMode) ? "true" : "false";
String trendString = ("USE_ID").equals(addRunToTrendReport) ? String.format(", TrendReportID = '%s'",trendReportId) : "";

return String.format("[Domain='%s', Project='%s', TestID='%s', " +
"TestInstanceID='%s', TimeslotDuration='%s', PostRunAction='%s'%s%s]",
return String.format("[PCServer='%s', User='%s', Domain='%s', Project='%s', TestID='%s', " +
"TestInstanceID='%s', TimeslotDuration='%s', PostRunAction='%s', " +
"VUDsMode='%s'%s, HTTPSProtocol='%s']",

almDomain, almProject, testId, testInstanceId,
timeslotDuration, postRunAction.getValue(), vudsModeString, trendString,HTTPSProtocol);
pcServerName, almUserName, almDomain, almProject, testId,
testInstanceId, timeslotDuration, postRunAction.getValue(),
vudsModeString, trendString, HTTPSProtocol);
}


public String getTrendReportId() {
return trendReportId;
}

public String getTrendReportId(boolean fromPcClient) {
return useParameterIfNeeded(buildParameters,trendReportId);
}

public void setTrendReportId(String trendReportId){
this.trendReportId = trendReportId;
}
Expand All @@ -223,17 +284,7 @@ public String isHTTPSProtocol(){
}

public void setBuildParameters(String buildParameters){
//this.buildParameters=buildParameters;
this.pcServerName=useParameterIfNeeded(buildParameters,this.pcServerName);
this.almUserName=useParameterIfNeeded(buildParameters,this.almUserName);
this.almDomain = useParameterIfNeeded(buildParameters,this.almDomain);
this.almProject = useParameterIfNeeded(buildParameters,this.almProject);
this.testId = useParameterIfNeeded(buildParameters,this.testId);
this.testInstanceId = useParameterIfNeeded(buildParameters,this.testInstanceId);
this.trendReportId = useParameterIfNeeded(buildParameters,this.trendReportId);
String guid="905fe758-94bd-4cbe-b377-affecd6bbdb3";
String parametrizedPassword = useParameterForPasswordIfNeeded(buildParameters,guid);
this.almPassword = parametrizedPassword.equals(guid)? this.almPassword:setPassword(parametrizedPassword);
this.buildParameters = buildParameters;
}

private static String useParameterIfNeeded (String buildParameters,String attribute){
Expand All @@ -251,14 +302,12 @@ private static String useParameterIfNeeded (String buildParameters,String attrib
return attribute;
}

private static String useParameterForPasswordIfNeeded (String buildParameters, String almPassword){
private SecretContainer useParameterForAlmPasswordIfNeeded (String buildParameters, SecretContainer almPassword, String expectedAlmPasswordParameterName ){
if (buildParameters!=null) {
String expectedAlmPasswordParameterName = "PCPASSWORD";
String almPasswordFromParameter="";
String[] buildParametersArray = buildParameters.replace("{", "").replace("}", "").split(",");
for (String buildParameter : buildParametersArray) {
if (buildParameter.trim().startsWith(expectedAlmPasswordParameterName + "=")) {
return buildParameter.trim().replace(expectedAlmPasswordParameterName + "=", "");
return setPassword(buildParameter.trim().replace(expectedAlmPasswordParameterName + "=", ""));
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/hpe/application/automation/tools/pc/PcClient.java
Expand Up @@ -68,10 +68,10 @@ public PcClient(PcModel pcModel, PrintStream logger) {
try {
model = pcModel;

if(model.getProxyOutURL() != null && !model.getProxyOutURL().isEmpty()){
logger.println("Using proxy: " + model.getProxyOutURL());
if(model.getProxyOutURL(true) != null && !model.getProxyOutURL(true).isEmpty()){
logger.println("Using proxy: " + model.getProxyOutURL(true));
}
restProxy = new PcRestProxy(model.isHTTPSProtocol(),model.getPcServerName(), model.getAlmDomain(), model.getAlmProject(),logger, model.getProxyOutURL(),model.getProxyOutUser(),model.getProxyOutPassword());
restProxy = new PcRestProxy(model.isHTTPSProtocol(),model.getPcServerName(true), model.getAlmDomain(true), model.getAlmProject(true),logger, model.getProxyOutURL(true),model.getProxyOutUser(true),model.getProxyOutPassword(true));
this.logger = logger;
}catch (PcException e){
logger.println(e.getMessage());
Expand All @@ -87,9 +87,9 @@ public <T extends PcRestProxy> PcClient(PcModel pcModel, PrintStream logger, T p

public boolean login() {
try {
String user = model.getAlmUserName();
logger.println(String.format("Trying to login\n[PCServer='%s://%s', User='%s']",model.isHTTPSProtocol(), model.getPcServerName(), user));
loggedIn = restProxy.authenticate(user, model.getAlmPassword().toString());
String user = model.getAlmUserName(true);
logger.println(String.format("Trying to login\n[PCServer='%s://%s', User='%s']",model.isHTTPSProtocol(), model.getPcServerName(true), user));
loggedIn = restProxy.authenticate(user, model.getAlmPassword(true).toString());
} catch (PcException e) {
logger.println(e.getMessage());
// stackTraceToString(e);
Expand Down Expand Up @@ -120,11 +120,11 @@ public int startRun() throws NumberFormatException, ClientProtocolException, PcE



int testID = Integer.parseInt(model.getTestId());
int testID = Integer.parseInt(model.getTestId(true));
int testInstance = getCorrectTestInstanceID(testID);
setCorrectTrendReportID();

logger.println(String.format("\nExecuting Load Test: \n====================\nTest ID: %s \nTest Instance ID: %s \nTimeslot Duration: %s \nPost Run Action: %s \nUse VUDS: %s\n====================\n", Integer.parseInt(model.getTestId()), testInstance, model.getTimeslotDuration() ,model.getPostRunAction().getValue(),model.isVudsMode()));
logger.println(String.format("\nExecuting Load Test: \n====================\nTest ID: %s \nTest Instance ID: %s \nTimeslot Duration: %s \nPost Run Action: %s \nUse VUDS: %s\n====================\n", Integer.parseInt(model.getTestId(true)), testInstance, model.getTimeslotDuration() ,model.getPostRunAction().getValue(),model.isVudsMode()));
// logger.println("Sending run request:\n" + model.runParamsToString());
PcRunResponse response = restProxy.startRun(testID,
testInstance,
Expand Down Expand Up @@ -171,13 +171,13 @@ private int getCorrectTestInstanceID(int testID) throws IOException, PcException
return Integer.parseInt(null);
}
}
return Integer.parseInt(model.getTestInstanceId());
return Integer.parseInt(model.getTestInstanceId(true));
}

private void setCorrectTrendReportID() throws IOException, PcException {
// If the user selected "Use trend report associated with the test" we want the report ID to be the one from the test
if (("ASSOCIATED").equals(model.getAddRunToTrendReport())){
PcTest pcTest = restProxy.getTestData(Integer.parseInt(model.getTestId()));
PcTest pcTest = restProxy.getTestData(Integer.parseInt(model.getTestId(true)));
if (pcTest.getTrendReportId() > -1)
model.setTrendReportId(String.valueOf(pcTest.getTrendReportId()));
else{
Expand All @@ -191,7 +191,7 @@ private void setCorrectTrendReportID() throws IOException, PcException {
}

public String getTestName() throws IOException, PcException{
PcTest pcTest = restProxy.getTestData(Integer.parseInt(model.getTestId()));
PcTest pcTest = restProxy.getTestData(Integer.parseInt(model.getTestId(true)));
return pcTest.getTestName();
}

Expand Down Expand Up @@ -317,7 +317,7 @@ public PcRunEventLog getRunEventLog(int runId){
public void addRunToTrendReport(int runId, String trendReportId)
{

TrendReportRequest trRequest = new TrendReportRequest(model.getAlmProject(), runId, null);
TrendReportRequest trRequest = new TrendReportRequest(model.getAlmProject(true), runId, null);
logger.println("Adding run: " + runId + " to trend report: " + trendReportId);
try {
restProxy.updateTrendReport(trendReportId, trRequest);
Expand Down
Expand Up @@ -362,7 +362,7 @@ private boolean validatePcForm() {
name = name.replace(prefix, "").toLowerCase();
for (Method modelMethod : modelMethods) {
String modelMethodName = modelMethod.getName();
if (modelMethodName.toLowerCase().equals("get" + name)) {
if (modelMethodName.toLowerCase().equals("get" + name) && modelMethod.getParameterTypes().length==0) {
try {
Object obj = FormValidation.ok();
if (!(name.equals("testinstanceid")&& pcModel.getAutoTestInstanceID().equals("AUTO"))){
Expand All @@ -374,7 +374,7 @@ private boolean validatePcForm() {
}
break;
} catch (Exception e) {
logger.println(e);
logger.println("method.getName() = " + method.getName() + "\nname = " + name + "\nmodelMethodName = " + modelMethodName + "\nexception = " + e + "\n");
}
}
}
Expand Down

0 comments on commit 5c3db55

Please sign in to comment.