Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
package com.adm.bamboo.plugin.performancecenter;

import com.atlassian.bamboo.collections.ActionParametersMap;
import com.atlassian.bamboo.task.AbstractTaskConfigurator;
import com.atlassian.bamboo.task.TaskDefinition;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.adm.bamboo.plugin.performancecenter.impl.PostRunAction;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;

/**
* Created by bemh on 7/23/2017.
*/
public class TaskConfigurator extends AbstractTaskConfigurator {

public static final String PC_SERVER ="PC Server";
public static final String USER ="User name";
public static final String HTTPS ="https";
public static final String PASSWORD ="Password";
public static final String DOMAIN ="Domain";
public static final String PROJECT ="PC Project";
public static final String TEST_ID ="Test ID";
public static final String TEST_INSTANCE_ID ="Test Instance ID";
public static final String TEST_INSTANCE_ID_RADIO ="TestInstanceIDRadio";
public static final String LOCAL_PROXY ="Local Proxy";
public static final String PROXY_USER ="ProxyUser";
public static final String PROXY_PASSWORD ="ProxyPassword";
public static final String POST_RUN_ACTION = "postRunAction";
public static final String TRENDING_RADIO ="trendingRadio";
public static final String TREND_REPORT_ID ="Trend Report ID";
public static final String TIMESLOT_HOURS ="Hours";
public static final String TIMESLOT_MINUTES ="Minutes";
public static final String VUDS ="vuds";
public static final String SLA ="sla";


public Map<String,String> postRunActionMap = new LinkedHashMap<String, String>();
public Map<String,String> testInstanceMap = new LinkedHashMap<String, String>();
public Map<String,String> trendReportMap = new LinkedHashMap<String, String>();


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";

ArrayList<String> localDAtaArray = new ArrayList<String>();




// Convert the params from the ui into a config map to be stored in the database for being used by the task.
public Map<String, String> generateTaskConfigMap(final ActionParametersMap params, final TaskDefinition previousTaskDefinition)
{
final Map<String, String> config = super.generateTaskConfigMap(params, previousTaskDefinition);

config.put(PC_SERVER, params.getString(PC_SERVER));
config.put(USER, params.getString(USER));
config.put(HTTPS, params.getString(HTTPS));
config.put(PASSWORD, params.getString(PASSWORD));
config.put(DOMAIN, params.getString(DOMAIN));
config.put(PROJECT, params.getString(PROJECT));
config.put(TEST_ID, params.getString(TEST_ID));
config.put(TEST_INSTANCE_ID, params.getString(TEST_INSTANCE_ID));
config.put(TEST_INSTANCE_ID_RADIO, params.getString(TEST_INSTANCE_ID_RADIO));
config.put(LOCAL_PROXY, params.getString(LOCAL_PROXY));
config.put(PROXY_USER, params.getString(PROXY_USER));
config.put(PROXY_PASSWORD, params.getString(PROXY_PASSWORD));
config.put(POST_RUN_ACTION, params.getString(POST_RUN_ACTION));
config.put(TREND_REPORT_ID, params.getString(TREND_REPORT_ID));
config.put(TRENDING_RADIO, params.getString(TRENDING_RADIO));
config.put(TIMESLOT_HOURS, params.getString(TIMESLOT_HOURS));
config.put(TIMESLOT_MINUTES, params.getString(TIMESLOT_MINUTES));
config.put(VUDS, params.getString(VUDS));
config.put(SLA, params.getString(SLA));


return config;
}

// Validate the params submitted from the UI for this task definition
public void validate(final ActionParametersMap params, final ErrorCollection errorCollection) {
// array with parameters we want to validate
updateLocalArray();

super.validate(params, errorCollection);

//final String PCServerValue = params.getString(PC_SERVER);
for (String p : localDAtaArray) {
String val = params.getString(p);
if ((StringUtils.equals(p, TEST_INSTANCE_ID) && !StringUtils.equals(params.getString("TestInstanceIDRadio"), "AUTO"))
|| StringUtils.equals(p, TEST_ID)
|| (StringUtils.equals(p, TREND_REPORT_ID) && StringUtils.equals(params.getString("trendingRadio"), "USE_ID"))){
if (StringUtils.isEmpty(val)) {
errorCollection.addError(p, "Required!");
}else if(!StringUtils.isNumeric(val)){
errorCollection.addError(p, "Must be numeric!");
}
}else {
if (StringUtils.isEmpty(val) && !StringUtils.equals(p, PASSWORD) && !StringUtils.equals(p, TEST_INSTANCE_ID) && !StringUtils.equals(p, TREND_REPORT_ID)) {
errorCollection.addError(p, "Required!");
}
}
}

}



// array with parameters we want to validate
private void updateLocalArray(){
localDAtaArray.clear();

localDAtaArray.add(PC_SERVER);
localDAtaArray.add(USER);
localDAtaArray.add(PASSWORD);
localDAtaArray.add(DOMAIN);
localDAtaArray.add(PROJECT);
localDAtaArray.add(TEST_ID);
localDAtaArray.add(TEST_INSTANCE_ID_RADIO);
localDAtaArray.add(TEST_INSTANCE_ID);
localDAtaArray.add(TIMESLOT_HOURS);
localDAtaArray.add(TIMESLOT_MINUTES);
localDAtaArray.add(TREND_REPORT_ID);
// localDAtaArray.add(POST_RUN_ACTION);


postRunActionMap.put(PostRunAction.DO_NOTHING.getValue().replaceAll(" ","_"), PostRunAction.DO_NOTHING.getValue()); //"Do Not Collate"
postRunActionMap.put(PostRunAction.COLLATE.getValue().replaceAll(" ","_"),PostRunAction.COLLATE.getValue()); // "Collate Results"
postRunActionMap.put(PostRunAction.COLLATE_AND_ANALYZE.getValue().replaceAll(" ","_"),PostRunAction.COLLATE_AND_ANALYZE.getValue()); //"Collate and Analyze")

testInstanceMap.put("AUTO","Automatically select existing or create new if none exists (Performance Center 12.55 or later)");
testInstanceMap.put("MANUAL","Manual selection");

trendReportMap.put("NO_TREND","Do Not Trend");
trendReportMap.put("ASSOCIATED","Use trend report associated with the test - Performance Center 12.55 or later");
trendReportMap.put("USE_ID","Add run to trend report with ID");


}


// Fill the saved data of the task when opening it after the last save
@Override
public void populateContextForEdit(final Map<String, Object> context, final TaskDefinition taskDefinition)
{
updateLocalArray();



context.put("postRunActionList", postRunActionMap);
context.put("testInstanceList",testInstanceMap);
context.put("trendReporList",trendReportMap);

// context.put("selectedPostRunAction",taskDefinition.getConfiguration().get(POST_RUN_ACTION));


context.put(PC_SERVER, taskDefinition.getConfiguration().get(PC_SERVER));
context.put(USER, taskDefinition.getConfiguration().get(USER));
context.put(HTTPS, taskDefinition.getConfiguration().get(HTTPS));
context.put(PASSWORD, taskDefinition.getConfiguration().get(PASSWORD));
context.put(DOMAIN, taskDefinition.getConfiguration().get(DOMAIN));
context.put(PROJECT, taskDefinition.getConfiguration().get(PROJECT));
context.put(TEST_ID, taskDefinition.getConfiguration().get(TEST_ID));
context.put(TEST_INSTANCE_ID, taskDefinition.getConfiguration().get(TEST_INSTANCE_ID));
context.put(TEST_INSTANCE_ID_RADIO, taskDefinition.getConfiguration().get(TEST_INSTANCE_ID_RADIO));
context.put(LOCAL_PROXY, taskDefinition.getConfiguration().get(LOCAL_PROXY));
context.put(PROXY_USER, taskDefinition.getConfiguration().get(PROXY_USER));
context.put(PROXY_PASSWORD, taskDefinition.getConfiguration().get(PROXY_PASSWORD));
context.put(POST_RUN_ACTION, taskDefinition.getConfiguration().get(POST_RUN_ACTION));
context.put(TRENDING_RADIO, taskDefinition.getConfiguration().get(TRENDING_RADIO));
context.put(TREND_REPORT_ID, taskDefinition.getConfiguration().get(TREND_REPORT_ID));
context.put(TIMESLOT_HOURS, taskDefinition.getConfiguration().get(TIMESLOT_HOURS));
context.put(TIMESLOT_MINUTES, taskDefinition.getConfiguration().get(TIMESLOT_MINUTES));
context.put(VUDS, taskDefinition.getConfiguration().get(VUDS));
context.put(SLA, taskDefinition.getConfiguration().get(SLA));



//config.put(POST_RUN_ACTION, params.getString(POST_RUN_ACTION));

}

// Fill the data of the task when opening it at the first time
@Override
public void populateContextForCreate(final Map<String, Object> context)
{
updateLocalArray();
super.populateContextForCreate(context);
context.put("postRunActionList", postRunActionMap);
context.put("testInstanceList",testInstanceMap);
context.put("trendReporList",trendReportMap);

context.put(TIMESLOT_HOURS,"0");
context.put(TIMESLOT_MINUTES,"30");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.adm.bamboo.plugin.performancecenter;

import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.task.*;
import com.adm.bamboo.plugin.performancecenter.impl.PcComponentsImpl;
import com.adm.bamboo.plugin.performancecenter.impl.PcException;
import com.adm.bamboo.plugin.performancecenter.impl.PostRunAction;

import java.io.IOException;


/**
* Created by bemh on 7/23/2017.
*/
public class TaskExecution implements TaskType
{

@Override
public TaskResult execute(final TaskContext taskContext) throws TaskException
{



final BuildLogger buildLogger = taskContext.getBuildLogger();
final String PC_SERVER = taskContext.getConfigurationMap().get(TaskConfigurator.PC_SERVER);
final String HTTPS = taskContext.getConfigurationMap().get(TaskConfigurator.HTTPS);
final String USER = taskContext.getConfigurationMap().get(TaskConfigurator.USER);
final String PASSWORD = taskContext.getConfigurationMap().get(TaskConfigurator.PASSWORD);
final String DOMAIN = taskContext.getConfigurationMap().get(TaskConfigurator.DOMAIN);
final String PROJECT = taskContext.getConfigurationMap().get(TaskConfigurator.PROJECT);
final String TEST_ID = taskContext.getConfigurationMap().get(TaskConfigurator.TEST_ID);
final String TEST_INSTANCE_ID_RADIO = taskContext.getConfigurationMap().get(TaskConfigurator.TEST_INSTANCE_ID_RADIO);
final String TEST_INSTANCE_ID = taskContext.getConfigurationMap().get(TaskConfigurator.TEST_INSTANCE_ID);
final String LOCAL_PROXY = taskContext.getConfigurationMap().get(TaskConfigurator.LOCAL_PROXY);
final String PROXY_USER = taskContext.getConfigurationMap().get(TaskConfigurator.PROXY_USER);
final String PROXY_PASSWORD = taskContext.getConfigurationMap().get(TaskConfigurator.PROXY_PASSWORD);
final String POST_RUN_ACTION = taskContext.getConfigurationMap().get(TaskConfigurator.POST_RUN_ACTION);
final String TRENDING_RADIO = taskContext.getConfigurationMap().get(TaskConfigurator.TRENDING_RADIO);
final String TREND_REPORT_ID = taskContext.getConfigurationMap().get(TaskConfigurator.TREND_REPORT_ID);
final String TIMESLOT_HOURS = taskContext.getConfigurationMap().get(TaskConfigurator.TIMESLOT_HOURS);
final String TIMESLOT_MINUTES = taskContext.getConfigurationMap().get(TaskConfigurator.TIMESLOT_MINUTES);
final String VUDS = taskContext.getConfigurationMap().get(TaskConfigurator.VUDS);
final String SLA = taskContext.getConfigurationMap().get(TaskConfigurator.SLA);
//String workingDirPath = String.valueOf(taskContext.getWorkingDirectory());
String runID;


PcComponentsImpl r = new PcComponentsImpl(taskContext,buildLogger,PC_SERVER,USER,PASSWORD,DOMAIN,PROJECT,TEST_ID,TEST_INSTANCE_ID_RADIO,TEST_INSTANCE_ID,TIMESLOT_HOURS,TIMESLOT_MINUTES, convertStringBackToPostRunAction(POST_RUN_ACTION),Boolean.parseBoolean(VUDS),Boolean.parseBoolean(SLA),"",TRENDING_RADIO,TREND_REPORT_ID,Boolean.parseBoolean(HTTPS),LOCAL_PROXY,PROXY_USER,PROXY_PASSWORD);


try {
if (!r.pcAuthenticate())
throw new PcException("Unable to login");
buildLogger.addBuildLogEntry("Executing Load Test:");
buildLogger.addBuildLogEntry("====================");
buildLogger.addBuildLogEntry("Test ID:" + TEST_ID);
buildLogger.addBuildLogEntry("Test Instance ID:" + TEST_INSTANCE_ID);
buildLogger.addBuildLogEntry("Timeslot Duration::" + TIMESLOT_HOURS + ":" + TIMESLOT_MINUTES + " (h:mm)");
buildLogger.addBuildLogEntry("Post Run Action:" + POST_RUN_ACTION);
buildLogger.addBuildLogEntry("Use VUDS:" + ("true".equals(VUDS.toLowerCase())?"true":"false"));

buildLogger.addBuildLogEntry("====================");
runID = r.startRun();
buildLogger.addBuildLogEntry("====================");



} catch (IOException e) {
e.printStackTrace();
buildLogger.addErrorLogEntry("Error while executing load test: " + e.toString());
return TaskResultBuilder.newBuilder(taskContext).failed().build();
} catch (PcException e) {
e.printStackTrace();
buildLogger.addErrorLogEntry("Error while executing load test: " + e.toString());
return TaskResultBuilder.newBuilder(taskContext).failed().build();
} catch (InterruptedException e) {
e.printStackTrace();
buildLogger.addErrorLogEntry("Error while executing load test: " + e.toString());
return TaskResultBuilder.newBuilder(taskContext).failed().build();
}

return TaskResultBuilder.newBuilder(taskContext).success().build();
}



private PostRunAction convertStringBackToPostRunAction(String postRunAction){
for(PostRunAction p: PostRunAction.values()){
if(postRunAction.replaceAll("_"," ").equals(p.getValue())){
return p;
}
}
return PostRunAction.DO_NOTHING;

}



}


Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.adm.bamboo.plugin.performancecenter.impl;

/***
*
* @author Effi Bar-She'an
* @author Dani Schreiber
*
*/
public class Base64Encoder {

private final static char[] ALPHABET =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
private static int[] _toInt = new int[128];

static {
for (int i = 0; i < ALPHABET.length; i++) {
_toInt[ALPHABET[i]] = i;
}
}

/**
* Translates the specified byte array into Base64 string.
*
* @param buf
* the byte array (not null)
* @return the translated Base64 string (not null)
*/
public static String encode(byte[] buf) {

int size = buf.length;
char[] ar = new char[((size + 2) / 3) * 4];
int a = 0;
int i = 0;
while (i < size) {
byte b0 = buf[i++];
byte b1 = (i < size) ? buf[i++] : 0;
byte b2 = (i < size) ? buf[i++] : 0;

int mask = 0x3F;
ar[a++] = ALPHABET[(b0 >> 2) & mask];
ar[a++] = ALPHABET[((b0 << 4) | ((b1 & 0xFF) >> 4)) & mask];
ar[a++] = ALPHABET[((b1 << 2) | ((b2 & 0xFF) >> 6)) & mask];
ar[a++] = ALPHABET[b2 & mask];
}
switch (size % 3) {
case 1:
ar[--a] = '=';
case 2:
ar[--a] = '=';
break;
}

return new String(ar);
}
}
Loading