From 540daba6cb3bf7256fdd581576075f3823cda79f Mon Sep 17 00:00:00 2001 From: "Hanan.Bem" Date: Sun, 22 Oct 2017 15:41:27 +0300 Subject: [PATCH] first commit conjoint plugin --- .../performancecenter/TaskConfigurator.java | 200 ++++++++ .../performancecenter/TaskExecution.java | 101 ++++ .../performancecenter/impl/Base64Encoder.java | 55 ++ .../impl/PcClientBamboo.java | 468 ++++++++++++++++++ .../impl/PcComponentsImpl.java | 148 ++++++ .../impl/PcErrorResponse.java | 49 ++ .../performancecenter/impl/PcException.java | 12 + .../performancecenter/impl/PcModelBamboo.java | 183 +++++++ .../performancecenter/impl/PcRestProxy.java | 356 +++++++++++++ .../performancecenter/impl/PcRunEventLog.java | 51 ++ .../impl/PcRunEventLogRecord.java | 72 +++ .../performancecenter/impl/PcRunRequest.java | 94 ++++ .../performancecenter/impl/PcRunResponse.java | 61 +++ .../performancecenter/impl/PcRunResult.java | 61 +++ .../performancecenter/impl/PcRunResults.java | 50 ++ .../plugin/performancecenter/impl/PcTest.java | 36 ++ .../performancecenter/impl/PcTestData.java | 68 +++ .../impl/PcTestInstance.java | 31 ++ .../impl/PcTestInstances.java | 32 ++ .../performancecenter/impl/PcTestSet.java | 37 ++ .../performancecenter/impl/PcTestSets.java | 32 ++ .../impl/PcTrendReportMetaData.java | 84 ++++ .../performancecenter/impl/PcTrendedRun.java | 60 +++ .../performancecenter/impl/PostRunAction.java | 18 + .../performancecenter/impl/RESTConstants.java | 27 + .../impl/ReleaseTimeslot.java | 57 +++ .../performancecenter/impl/RunState.java | 66 +++ .../impl/TestInstanceCreateRequest.java | 54 ++ .../performancecenter/impl/TimeInterval.java | 81 +++ .../impl/TimeslotDuration.java | 59 +++ .../impl/TrendReportMonitorsDataRow.java | 93 ++++ .../impl/TrendReportMonitorsDataRows.java | 54 ++ .../impl/TrendReportRegularDataRow.java | 83 ++++ .../impl/TrendReportRegularDataRows.java | 54 ++ .../impl/TrendReportRequest.java | 54 ++ .../impl/TrendReportTransactionDataRoot.java | 65 +++ .../impl/TrendReportTransactionDataRow.java | 167 +++++++ .../impl/TrendReportTransactionDataRows.java | 54 ++ .../impl/TrendReportTypes.java | 62 +++ .../performancecenter/impl/TrendedRange.java | 45 ++ src/main/resources/atlassian-plugin.xml | 9 +- src/main/resources/images/pc/pc_64x64.png | Bin 0 -> 1019 bytes .../performancecenter/configurePC.ftl | 245 +++++++++ 43 files changed, 3686 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/TaskConfigurator.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/TaskExecution.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/Base64Encoder.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcClientBamboo.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcComponentsImpl.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcErrorResponse.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcException.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcModelBamboo.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRestProxy.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunEventLog.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunEventLogRecord.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunRequest.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResponse.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResult.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResults.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTest.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestData.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestInstance.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestInstances.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestSet.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestSets.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTrendReportMetaData.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTrendedRun.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PostRunAction.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/RESTConstants.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/ReleaseTimeslot.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/RunState.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TestInstanceCreateRequest.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TimeInterval.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TimeslotDuration.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportMonitorsDataRow.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportMonitorsDataRows.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRegularDataRow.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRegularDataRows.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRequest.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRoot.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRow.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRows.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTypes.java create mode 100644 src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendedRange.java create mode 100644 src/main/resources/images/pc/pc_64x64.png create mode 100644 src/main/resources/templates/performancecenter/configurePC.ftl diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/TaskConfigurator.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/TaskConfigurator.java new file mode 100644 index 0000000..0becd33 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/TaskConfigurator.java @@ -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 postRunActionMap = new LinkedHashMap(); + public Map testInstanceMap = new LinkedHashMap(); + public Map trendReportMap = new LinkedHashMap(); + + + 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 localDAtaArray = new ArrayList(); + + + + + // Convert the params from the ui into a config map to be stored in the database for being used by the task. + public Map generateTaskConfigMap(final ActionParametersMap params, final TaskDefinition previousTaskDefinition) + { + final Map 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 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 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"); + } + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/TaskExecution.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/TaskExecution.java new file mode 100644 index 0000000..4be6223 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/TaskExecution.java @@ -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; + + } + + + +} + + diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/Base64Encoder.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/Base64Encoder.java new file mode 100644 index 0000000..9375907 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/Base64Encoder.java @@ -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); + } +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcClientBamboo.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcClientBamboo.java new file mode 100644 index 0000000..435122d --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcClientBamboo.java @@ -0,0 +1,468 @@ +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.atlassian.bamboo.build.logger.BuildLogger; +import com.atlassian.bamboo.plan.artifact.ArtifactDefinitionContextImpl; +import com.atlassian.bamboo.task.TaskContext; +import org.apache.commons.io.IOUtils; +import org.apache.http.client.ClientProtocolException; +//import org.hibernate.cfg.beanvalidation.IntegrationException; + + +import java.beans.IntrospectionException; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + + +/** + * Created by bemh on 8/6/2017. + */ +public class PcClientBamboo { + + + private static final String artifactsDirectoryName = "archive"; + public static final String artifactsResourceName = "artifact"; + public static final String runReportStructure = "%s/%s/performanceTestsReports/pcRun"; + public static final String trendReportStructure = "%s/%s/performanceTestsReports/TrendReports"; + public static final String pcReportArchiveName = "Reports.zip"; + public static final String pcReportFileName = "Report.html"; + private static final String RUNID_BUILD_VARIABLE = "HP_RUN_ID"; + + public static final String TRENDED = "Trended"; + public static final String PENDING = "Pending"; + public static final String PUBLISHING = "Publishing"; + public static final String ERROR = "Error"; + + private PcModelBamboo model; + private TaskContext taskContext; + private PcRestProxy restProxy; + private boolean loggedIn; + private BuildLogger buildLogger; + + private PrintStream ps; + + public static final String COLLATE = "COLLATE"; + public static final String COLLATE_ANALYZE = "COLLATE_AND_ANALYZE"; + public static final String DO_NOTHING = "DO_NOTHING"; + + public PcClientBamboo(PcModelBamboo pcModel, TaskContext taskContext, BuildLogger buildLogger) { + try { + model = pcModel; + this.taskContext = taskContext; + + if(model.getProxyOutURL() != null && !model.getProxyOutURL().isEmpty()){ + buildLogger.addBuildLogEntry("Using proxy: " + model.getProxyOutURL()); + } + restProxy = new PcRestProxy(model.isHTTPSProtocol(),model.getPcServerName(), model.getAlmDomain(), model.getAlmProject(), model.getProxyOutURL(),model.getProxyOutUser(),model.getProxyOutPassword()); + this.buildLogger = buildLogger; + }catch (PcException e){ + buildLogger.addBuildLogEntry(e.getMessage()); + } + + } + + public boolean login() { + try { + String user = model.getAlmUserName(); + buildLogger.addBuildLogEntry(String.format("Trying to login\n[PCServer='%s://%s', User='%s']",model.isHTTPSProtocol(), model.getPcServerName(), user)); + loggedIn = restProxy.authenticate(user, model.getAlmPassword().toString()); + } catch (PcException e) { + buildLogger.addBuildLogEntry(e.getMessage()); + } catch (Exception e) { + buildLogger.addBuildLogEntry(String.valueOf(e)); + } + buildLogger.addBuildLogEntry(String.format("Login %s", loggedIn ? "succeeded" : "failed")); + return loggedIn; + } + + + public boolean isLoggedIn() { + return loggedIn; + } + + public int startRun() throws NumberFormatException, ClientProtocolException, PcException, IOException { + int testID = Integer.parseInt(model.getTestId()); + int testInstance = getCorrectTestInstanceID(testID); + setCorrectTrendReportID(); + + PcRunResponse response = restProxy.startRun(testID, + testInstance, + model.getTimeslotDuration(), + model.getPostRunAction().getValue(), + model.isVudsMode()); + buildLogger.addBuildLogEntry(String.format("\nRun started (TestID: %s, RunID: %s, TimeslotID: %s)\n", + response.getTestID(), response.getID(), response.getTimeslotID())); + return response.getID(); + } + + private int getCorrectTestInstanceID(int testID) throws IOException, PcException { + if("AUTO".equals(model.getAutoTestInstanceID())){ + try { + + + buildLogger.addBuildLogEntry("Searching for available Test Instance"); + PcTestInstances pcTestInstances = restProxy.getTestInstancesByTestId(testID); + int testInstanceID = 0; + if (pcTestInstances != null && pcTestInstances.getTestInstancesList() != null){ + PcTestInstance pcTestInstance = pcTestInstances.getTestInstancesList().get(pcTestInstances.getTestInstancesList().size()-1); + testInstanceID = pcTestInstance.getInstanceId(); + buildLogger.addBuildLogEntry("Found testInstanceId: " + testInstanceID); + }else{ + buildLogger.addBuildLogEntry("Could not find available TestInstanceID, Creating Test Instance."); + buildLogger.addBuildLogEntry("Searching for available TestSet"); + // Get a random TestSet + PcTestSets pcTestSets = restProxy.GetAllTestSets(); + if (pcTestSets !=null && pcTestSets.getPcTestSetsList() !=null){ + PcTestSet pcTestSet = pcTestSets.getPcTestSetsList().get(pcTestSets.getPcTestSetsList().size()-1); + int testSetID = pcTestSet.getTestSetID(); + buildLogger.addBuildLogEntry(String.format("Creating Test Instance with testID: %s and TestSetID: %s", testID,testSetID)); + testInstanceID = restProxy.createTestInstance(testID,testSetID); + buildLogger.addBuildLogEntry(String.format("Test Instance with ID : %s has been created successfully.", testInstanceID)); + }else{ + String msg = "No TestSetID available in project, please create a testset from Performance Center UI"; + buildLogger.addBuildLogEntry(msg); + throw new PcException(msg); + } + } + return testInstanceID; + } catch (Exception e){ + buildLogger.addBuildLogEntry(String.format("getCorrectTestInstanceID failed, reason: %s",e)); + return Integer.parseInt(null); + } + } + return Integer.parseInt(model.getTestInstanceId()); + } + + 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())); + if (pcTest.getTrendReportId() > -1) + model.setTrendReportId(String.valueOf(pcTest.getTrendReportId())); + else{ + String msg = "No trend report ID is associated with the test.\n" + + "Please turn Automatic Trending on for the test through Performance Center UI.\n" + + "Alternatively you can check 'Add run to trend report with ID' on Jenkins job configuration."; + throw new PcException(msg); + } + } + + } + + public String getTestName() throws IOException, PcException{ + PcTest pcTest = restProxy.getTestData(Integer.parseInt(model.getTestId())); + return pcTest.getTestName(); + } + + public PcRunResponse waitForRunCompletion(int runId) throws InterruptedException, ClientProtocolException, PcException, IOException { + + return waitForRunCompletion(runId, 5000); + } + + public PcRunResponse waitForRunCompletion(int runId, int interval) throws InterruptedException, ClientProtocolException, PcException, IOException { + RunState state = RunState.UNDEFINED; + if (model.getPostRunAction().toString().equals(DO_NOTHING)) { + state = RunState.BEFORE_COLLATING_RESULTS; + + } else if (model.getPostRunAction().toString().equals(COLLATE)) { + state = RunState.BEFORE_CREATING_ANALYSIS_DATA; + + } else if (model.getPostRunAction().toString().equals(COLLATE_ANALYZE)) { + state = RunState.FINISHED; + + } + return waitForRunState(runId, state, interval); + } + + + private PcRunResponse waitForRunState(int runId, RunState completionState, int interval) throws InterruptedException, + ClientProtocolException, PcException, IOException { + + int counter = 0; + RunState[] states = {RunState.BEFORE_COLLATING_RESULTS,RunState.BEFORE_CREATING_ANALYSIS_DATA}; + PcRunResponse response = null; + RunState lastState = RunState.UNDEFINED; + do { + response = restProxy.getRunData(runId); + RunState currentState = RunState.get(response.getRunState()); + if (lastState.ordinal() < currentState.ordinal()) { + lastState = currentState; + buildLogger.addBuildLogEntry(String.format("RunID: %s - State = %s", runId, currentState.value())); + } + + // In case we are in state before collate or before analyze, we will wait 1 minute for the state to change otherwise we exit + // because the user probably stopped the run from PC or timeslot has reached the end. + if (Arrays.asList(states).contains(currentState)){ + counter++; + Thread.sleep(1000); + if(counter > 60 ){ + buildLogger.addBuildLogEntry(String.format("RunID: %s - Stopped from Performance Center side with state = %s", runId, currentState.value())); + break; + } + }else{ + counter = 0; + Thread.sleep(interval); + } + } while (lastState.ordinal() < completionState.ordinal()); + return response; + } + + public String publishRunReport(int runId, String reportDirectory) throws IOException, PcException, InterruptedException { + + + PcRunResults runResultsList = restProxy.getRunResults(runId); + if (runResultsList.getResultsList() != null){ + for (PcRunResult result : runResultsList.getResultsList()) { + if (result.getName().equals(pcReportArchiveName)) { + File dir = new File(reportDirectory + File.separator + "Reports");// taskContext.getBuildContext().getBuildNumber()); + dir.mkdirs(); + String reportArchiveFullPath = dir.getCanonicalPath() + IOUtils.DIR_SEPARATOR + pcReportArchiveName; + buildLogger.addBuildLogEntry("Publishing analysis report"); + restProxy.GetRunResultData(runId, result.getID(), reportArchiveFullPath); + File fp = new File(reportArchiveFullPath); + unzip(reportArchiveFullPath,fp.getParent().toString()); + String reportFile = dir.getPath() + File.separator + pcReportFileName; + publishHTMLReportToArtifact(); + //Deleting the unziped report file + // FileUtils.deleteDirectory(dir); + return reportFile; + } + } + } + buildLogger.addBuildLogEntry("Failed to get run report"); + return null; + } + + public void publishHTMLReportToArtifact(){ + Map config = new HashMap<>(); + + ArtifactDefinitionContextImpl artifact = new ArtifactDefinitionContextImpl("Build_" + String.valueOf(taskContext.getBuildContext().getBuildNumber()) + "_reports",false,null); + artifact.setCopyPattern("**/*"); + taskContext.getBuildContext().getArtifactContext().getDefinitionContexts().add(artifact); + } + + + public boolean logout() { + if (!loggedIn) + return true; + + boolean logoutSucceeded = false; + try { + logoutSucceeded = restProxy.logout(); + loggedIn = !logoutSucceeded; + } catch (PcException e) { + buildLogger.addBuildLogEntry(e.getMessage()); + } catch (Exception e) { + buildLogger.addBuildLogEntry(String.valueOf(e)); + } + buildLogger.addBuildLogEntry(String.format("Logout %s", logoutSucceeded ? "succeeded" : "failed")); + return logoutSucceeded; + } + + public boolean stopRun(int runId) { + boolean stopRunSucceeded = false; + try { + buildLogger.addBuildLogEntry("Stopping run"); + stopRunSucceeded = restProxy.stopRun(runId, "stop"); + } catch (PcException e) { + buildLogger.addBuildLogEntry(e.getMessage()); + } catch (Exception e) { + buildLogger.addBuildLogEntry(String.valueOf(e)); + } + buildLogger.addBuildLogEntry(String.format("Stop run %s", stopRunSucceeded ? "succeeded" : "failed")); + return stopRunSucceeded; + } + + public PcRunEventLog getRunEventLog(int runId){ + try { + return restProxy.getRunEventLog(runId); + } catch (PcException e) { + buildLogger.addBuildLogEntry(e.getMessage()); + } catch (Exception e) { + buildLogger.addBuildLogEntry(String.valueOf(e)); + } + return null; + } + + public void addRunToTrendReport(int runId, String trendReportId) + { + + TrendReportRequest trRequest = new TrendReportRequest(model.getAlmProject(), runId, null); + buildLogger.addBuildLogEntry("Adding run: " + runId + " to trend report: " + trendReportId); + try { + restProxy.updateTrendReport(trendReportId, trRequest); + buildLogger.addBuildLogEntry("Publishing run: " + runId + " on trend report: " + trendReportId); + } + catch (PcException e) { + buildLogger.addBuildLogEntry("Failed to add run to trend report: " + e.getMessage()); + } + catch (IOException e) { + buildLogger.addBuildLogEntry("Failed to add run to trend report: Problem connecting to PC Server"); + } + } + + public void waitForRunToPublishOnTrendReport(int runId, String trendReportId) throws PcException,IOException,InterruptedException{ + + ArrayList trendReportMetaDataResultsList; + boolean publishEnded = false; + int counter = 0; + + do { + trendReportMetaDataResultsList = restProxy.getTrendReportMetaData(trendReportId); + + if (trendReportMetaDataResultsList.isEmpty()) break; + + for (PcTrendedRun result : trendReportMetaDataResultsList) { + + if (result.getRunID() != runId) continue; + + if (result.getState().equals(TRENDED) || result.getState().equals(ERROR)){ + publishEnded = true; + buildLogger.addBuildLogEntry("Run: " + runId + " publishing status: "+ result.getState()); + break; + }else{ + Thread.sleep(5000); + counter++; + if(counter >= 120){ + String msg = "Error: Publishing didn't ended after 10 minutes, aborting..."; + throw new PcException(msg); + } + } + } + + }while (!publishEnded && counter < 120); + } + + + + /** + * Size of the buffer to read/write data + */ + private static final int BUFFER_SIZE = 4096; + /** + * Extracts a zip file specified by the zipFilePath to a directory specified by + * destDirectory (will be created if does not exists) + * @param zipFilePath + * @param destDirectory + * @throws IOException + */ + public void unzip(String zipFilePath, String destDirectory) throws IOException { + File destDir = new File(destDirectory); + if (!destDir.exists()) { + destDir.mkdir(); + } + ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath)); + ZipEntry entry = zipIn.getNextEntry(); + // iterates over entries in the zip file + while (entry != null) { + String filePath = destDirectory + File.separator + entry.getName(); + if (!entry.isDirectory()) { + // if the entry is a file, extracts it + extractFile(zipIn, filePath); + } else { + // if the entry is a directory, make the directory + File dir = new File(filePath); + dir.mkdir(); + } + zipIn.closeEntry(); + entry = zipIn.getNextEntry(); + } + zipIn.close(); + } + /** + * Extracts a zip entry (file entry) + * @param zipIn + * @param filePath + * @throws IOException + */ + private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); + byte[] bytesIn = new byte[BUFFER_SIZE]; + int read = 0; + while ((read = zipIn.read(bytesIn)) != -1) { + bos.write(bytesIn, 0, read); + } + bos.close(); + } + + + + public boolean downloadTrendReportAsPdf(String trendReportId, String directory) throws PcException { + + + try { + buildLogger.addBuildLogEntry("Downloading trend report: " + trendReportId + " in PDF format"); + InputStream in = restProxy.getTrendingPDF(trendReportId); + File dir = new File(directory); + if(!dir.exists()){ + dir.mkdirs(); + } + String filePath = directory + IOUtils.DIR_SEPARATOR + "trendReport" + trendReportId + ".pdf"; + Path destination = Paths.get(filePath); + Files.copy(in, destination, StandardCopyOption.REPLACE_EXISTING); + buildLogger.addBuildLogEntry("Trend report: " + trendReportId + " was successfully downloaded"); + buildLogger.addBuildLogEntry("View trend report in the Artifacts Tab."); + + } + catch (Exception e) { + + buildLogger.addBuildLogEntry("Failed to download trend report: " + e.getMessage()); + throw new PcException(e.getMessage()); + } + + return true; + + } + + + + + // This method will return a map with the following structure: + // for example: + // + // + // This function uses reflection since we know only at runtime which transactions data will be reposed from the rest request. + public Map getTrendReportByXML(String trendReportId, int runId, TrendReportTypes.DataType dataType, TrendReportTypes.PctType pctType, TrendReportTypes.Measurement measurement) throws IOException, PcException, IntrospectionException, NoSuchMethodException { + + Map measurmentsMap = new LinkedHashMap(); + measurmentsMap.put("RunId","_" + runId + "_"); + measurmentsMap.put("Trend Measurement Type",measurement.toString() + "_" + pctType.toString()); + + + + TrendReportTransactionDataRoot res = restProxy.getTrendReportByXML(trendReportId, runId); + + List RowsListObj = res.getTrendReportRoot(); + + for (int i=0; i< RowsListObj.size();i++){ + try { + + java.lang.reflect.Method rowListMethod = RowsListObj.get(i).getClass().getMethod("getTrendReport" + dataType.toString() + "DataRowList"); + + for ( Object DataRowObj : (ArrayList)rowListMethod.invoke(RowsListObj.get(i))) + { + if (DataRowObj.getClass().getMethod("getPCT_TYPE").invoke(DataRowObj).equals(pctType.toString())) + { + java.lang.reflect.Method method; + method = DataRowObj.getClass().getMethod("get" + measurement.toString()); + measurmentsMap.put(DataRowObj.getClass().getMethod("getPCT_NAME").invoke(DataRowObj).toString(),method.invoke(DataRowObj)==null?"":method.invoke(DataRowObj).toString()); + } + } + }catch (NoSuchMethodException e){ + // buildLogger.addBuildLogEntry("No such method exception: " + e); + } + catch (Exception e){ + buildLogger.addBuildLogEntry("Error on getTrendReportByXML: " + e); + } + } + + return measurmentsMap; + + + } +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcComponentsImpl.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcComponentsImpl.java new file mode 100644 index 0000000..9e0abd8 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcComponentsImpl.java @@ -0,0 +1,148 @@ +package com.adm.bamboo.plugin.performancecenter.impl; + + +import com.atlassian.bamboo.build.fileserver.DefaultBuildDirectoryManager; +import com.atlassian.bamboo.build.logger.BuildLogger; +import com.atlassian.bamboo.task.TaskContext; +import org.apache.http.client.CookieStore; +import org.apache.http.client.HttpClient; +import org.apache.http.client.protocol.ClientContext; +import org.apache.http.impl.client.BasicCookieStore; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.PoolingClientConnectionManager; +import org.apache.http.impl.conn.SchemeRegistryFactory; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; + +import java.io.File; +import java.io.IOException; + +import static com.adm.bamboo.plugin.performancecenter.impl.RunState.FINISHED; +import static com.adm.bamboo.plugin.performancecenter.impl.RunState.RUN_FAILURE; + + +/** + * Created by bemh on 7/23/2017. + */ +public class PcComponentsImpl { + + + HttpContext context = null; + HttpClient client = null; + TaskContext taskContext; + PcModelBamboo pcModel; + PcClientBamboo pcClient; + PcRunResponse response = null; + + String pcReportFile; + + BuildLogger buildLogger; + + + public PcComponentsImpl(TaskContext taskContext, BuildLogger buildLogger, String pcServerName, String almUserName, String almPassword, String almDomain, String almProject, + String testId, String autoTestInstanceID, String testInstanceId, String timeslotDurationHours, String timeslotDurationMinutes, + PostRunAction postRunAction, boolean vudsMode, boolean sla, String description, String addRunToTrendReport, String trendReportId, boolean HTTPSProtocol, String proxyOutURL, String proxyUser, String proxyPassword){ + +// public PcComponentsImpl(BuildLogger buildLogger){ + + CookieStore cookieStore; + context = new BasicHttpContext(); + this.taskContext = taskContext; + cookieStore = new BasicCookieStore(); + context.setAttribute(ClientContext.COOKIE_STORE, cookieStore); + this.buildLogger = buildLogger; + + PoolingClientConnectionManager cxMgr = new PoolingClientConnectionManager(SchemeRegistryFactory.createDefault()); + cxMgr.setMaxTotal(100); + cxMgr.setDefaultMaxPerRoute(20); + client = new DefaultHttpClient(cxMgr); + pcModel = new PcModelBamboo(pcServerName, almUserName,almPassword, almDomain, almProject,testId,autoTestInstanceID, testInstanceId,timeslotDurationHours,timeslotDurationMinutes, postRunAction,vudsMode,sla, description,addRunToTrendReport,trendReportId,HTTPSProtocol,proxyOutURL,proxyUser,proxyPassword); +// PcModelBamboo pcModel = new PcModelBamboo(PC_SERVER_NAME, ALM_USER_NAME,ALM_PASSWORD, ALM_DOMAIN, ALM_PROJECT,TEST_ID,TESTINSTANCEID, TEST_INSTANCE_ID,TIMESLOT_DURATION_HOURS,TIMESLOT_DURATION_MINUTES, POST_RUN_ACTION,VUDS_MODE, DESCRIPTION,ADD_RUN_TO_TREND_REPORT,TREND_REPORT_ID,IS_HTTPS,PROXY_OUT_URL); + pcClient = new PcClientBamboo(pcModel,taskContext,buildLogger); + + } + + + public Boolean pcAuthenticate() throws IOException, PcException { + + Boolean loggedIn = false; + loggedIn = pcClient.login(); + return loggedIn; + + } + + public String startRun() throws IOException, PcException, InterruptedException { + int runId = 0; + String eventLogString = ""; + boolean trendReportReady = false; + + + + try { + runId = pcClient.startRun(); + + response = pcClient.waitForRunCompletion(runId); + + + if (response != null && RunState.get(response.getRunState()) == FINISHED) { + DefaultBuildDirectoryManager defaultBuildDirectoryManager = new DefaultBuildDirectoryManager(); + pcReportFile = pcClient.publishRunReport(runId,String.valueOf(taskContext.getWorkingDirectory())); + + buildLogger.addBuildLogEntry("View analysis report of run: " + runId + ", in the Artifacts Tab."); + + // Adding the trend report section if ID has been set + if(("USE_ID").equals(pcModel.getAddRunToTrendReport()) && pcModel.getTrendReportId() != null && RunState.get(response.getRunState()) != RUN_FAILURE){ + pcClient.addRunToTrendReport(runId, pcModel.getTrendReportId()); + pcClient.waitForRunToPublishOnTrendReport(runId, pcModel.getTrendReportId()); + pcClient.downloadTrendReportAsPdf(pcModel.getTrendReportId(),getTrendReportsDirectory(runId)); + trendReportReady = true; + } + + // Adding the trend report if the Associated Trend report is selected. + if(("ASSOCIATED").equals(pcModel.getAddRunToTrendReport()) && RunState.get(response.getRunState()) != RUN_FAILURE){ + pcClient.addRunToTrendReport(runId, pcModel.getTrendReportId()); + pcClient.waitForRunToPublishOnTrendReport(runId, pcModel.getTrendReportId()); + pcClient.downloadTrendReportAsPdf(pcModel.getTrendReportId(), getTrendReportsDirectory(runId)); + trendReportReady = true; + } + + } else if (response != null && RunState.get(response.getRunState()).ordinal() > FINISHED.ordinal()) { + PcRunEventLog eventLog = pcClient.getRunEventLog(runId); + eventLogString = buildEventLogString(eventLog); + } + + + } catch (PcException e) { + e.printStackTrace(); + throw e; + } catch (IOException e) { + e.printStackTrace(); + throw e; + } catch (InterruptedException e) { + e.printStackTrace(); + throw e; + } + + return String.valueOf(runId); + } + + private String getTrendReportsDirectory(int runId) { +// return String.valueOf(taskContext.getWorkingDirectory()) + File.separator + taskContext.getBuildContext().getBuildNumber() + File.separator + "TrendReports"; + return String.valueOf(taskContext.getWorkingDirectory()) + File.separator + "Reports" + File.separator + "TrendReports"; + } + + + private String buildEventLogString(PcRunEventLog eventLog) { + + String logFormat = "%-5s | %-7s | %-19s | %s\n"; + StringBuilder eventLogStr = new StringBuilder("Event Log:\n\n" + String.format(logFormat, "ID", "TYPE", "TIME","DESCRIPTION")); + for (PcRunEventLogRecord record : eventLog.getRecordsList()) { + eventLogStr.append(String.format(logFormat, record.getID(), record.getType(), record.getTime(), record.getDescription())); + } + return eventLogStr.toString(); + } + + + + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcErrorResponse.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcErrorResponse.java new file mode 100644 index 0000000..7efc79a --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcErrorResponse.java @@ -0,0 +1,49 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +public class PcErrorResponse { + + @SuppressWarnings("unused") + private String xmlns = PcRestProxy.PC_API_XMLNS; + + public String ExceptionMessage; + + public int ErrorCode; + + public PcErrorResponse(String exceptionMessage, int errorCode) { + ExceptionMessage = exceptionMessage; + ErrorCode = errorCode; + } + + public static PcErrorResponse xmlToObject(String xml) { + XStream xstream = new XStream(); + xstream.setClassLoader(PcErrorResponse.class.getClassLoader()); + xstream.alias("Exception", PcErrorResponse.class); + return (PcErrorResponse) xstream.fromXML(xml); + + } + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcException.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcException.java new file mode 100644 index 0000000..0fb3e7d --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcException.java @@ -0,0 +1,12 @@ +package com.adm.bamboo.plugin.performancecenter.impl; + +public class PcException extends Exception { + + private static final long serialVersionUID = -4036530091360617367L; + + public PcException(String message) { + + super(message); + } + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcModelBamboo.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcModelBamboo.java new file mode 100644 index 0000000..83f5733 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcModelBamboo.java @@ -0,0 +1,183 @@ +package com.adm.bamboo.plugin.performancecenter.impl; + + +import java.util.Arrays; +import java.util.List; + +/** + * Created by bemh on 8/6/2017. + */ +public class PcModelBamboo { + + + + private final String pcServerName; + private final String almUserName; + private final String almPassword; + private final String almDomain; + private final String almProject; + private final String testId; + private final String testInstanceId; + private final String autoTestInstanceID; + private final TimeslotDuration timeslotDuration; + private final PostRunAction postRunAction; + private final boolean vudsMode; + private final boolean sla; + private final String description; + private final String addRunToTrendReport; + private String trendReportId; + private final boolean HTTPSProtocol; + private final String proxyOutURL; + private final String proxyOutUser; + private final String proxyOutPassword; + + + + public PcModelBamboo(String pcServerName, String almUserName, String almPassword, String almDomain, String almProject, + String testId,String autoTestInstanceID, String testInstanceId, String timeslotDurationHours, String timeslotDurationMinutes, + PostRunAction postRunAction, boolean vudsMode,boolean sla, String description, String addRunToTrendReport, String trendReportId, boolean HTTPSProtocol, String proxyOutURL,String proxyOutUser, String proxyOutPassword) { + + this.pcServerName = pcServerName; + this.almUserName = almUserName; + this.almPassword = almPassword; + this.almDomain = almDomain; + this.almProject = almProject; + this.testId = testId; + this.autoTestInstanceID = autoTestInstanceID; + this.testInstanceId = testInstanceId; + this.timeslotDuration = new TimeslotDuration(timeslotDurationHours, timeslotDurationMinutes); + this.postRunAction = postRunAction; + this.vudsMode = vudsMode; + this.sla = sla; + this.description = description; + this.addRunToTrendReport = addRunToTrendReport; + this.HTTPSProtocol = HTTPSProtocol; + this.trendReportId = trendReportId; + this.proxyOutURL = proxyOutURL; + this.proxyOutUser = proxyOutUser; + this.proxyOutPassword = proxyOutPassword; + } + +// protected SecretContainer setPassword(String almPassword) { +// +// SecretContainer secretContainer = new SecretContainerImpl(); +// secretContainer.initialize(almPassword); +// return secretContainer; +// } + + public String getPcServerName() { + + return this.pcServerName; + } + + public String getAlmUserName() { + + return this.almUserName; + } + + public String getAlmPassword() { + + return this.almPassword; + } + + public String getAlmDomain() { + + return this.almDomain; + } + + public String getAlmProject() { + + return this.almProject; + } + + public String getTestId() { + + return this.testId; + } + + public String getTestInstanceId() { + return this.testInstanceId; + } + + public String getAutoTestInstanceID(){ + return this.autoTestInstanceID; + } + + public TimeslotDuration getTimeslotDuration() { + + return this.timeslotDuration; + } + + public boolean isVudsMode() { + + return this.vudsMode; + } + + public PostRunAction getPostRunAction() { + + return this.postRunAction; + } + + public String getDescription() { + + return this.description; + } + + public boolean httpsProtocol(){ + return this.HTTPSProtocol; + } + + public String getProxyOutURL(){ + return this.proxyOutURL; + } + + public String getProxyOutUser(){ + return this.proxyOutUser; + } + + public String getProxyOutPassword(){ + return this.proxyOutPassword; + } + + public static List getPostRunActions() { + return Arrays.asList(PostRunAction.values()); + } + + + @Override + public String toString() { + + return String.format("[PCServer='%s', User='%s', %s", runParamsToString().substring(1)); + } + + public String runParamsToString() { + + String vudsModeString = (vudsMode) ? ", VUDsMode='true'" : ""; + 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]", + + almDomain, almProject, testId, testInstanceId, + timeslotDuration, postRunAction, vudsModeString, trendString,HTTPSProtocol); + } + + + public String getTrendReportId() { + return trendReportId; + } + + public void setTrendReportId(String trendReportId){ + this.trendReportId = trendReportId; + } + + public String getAddRunToTrendReport() { + return addRunToTrendReport; + } + + public String isHTTPSProtocol(){ + if (!HTTPSProtocol) + return "http"; + return "https"; + } +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRestProxy.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRestProxy.java new file mode 100644 index 0000000..94078b6 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRestProxy.java @@ -0,0 +1,356 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/* +* Implements the REST API methods for executing the loadtest +* */ +package com.adm.bamboo.plugin.performancecenter.impl; + + +import org.apache.commons.codec.CharEncoding; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpHeaders; +import org.apache.http.HttpHost; +import org.apache.http.HttpResponse; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.Credentials; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.CookieStore; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.methods.HttpGet; +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; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.PoolingClientConnectionManager; +import org.apache.http.impl.conn.SchemeRegistryFactory; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.apache.commons.httpclient.HttpStatus.*; + +public class PcRestProxy { + + protected static final String BASE_PC_API_URL = "%s://%s/LoadTest/rest"; + protected static final String BASE_PC_API_AUTHENTICATION_URL = BASE_PC_API_URL + "/authentication-point"; + protected static final String AUTHENTICATION_LOGIN_URL = BASE_PC_API_AUTHENTICATION_URL + "/authenticate"; + protected static final String AUTHENTICATION_LOGOUT_URL = BASE_PC_API_AUTHENTICATION_URL + "/logout"; + protected static final String PC_API_RESOURCES_TEMPLATE = BASE_PC_API_URL + "/domains/%s/projects/%s"; + protected static final String RUNS_RESOURCE_NAME = "Runs"; + protected static final String TESTS_RESOURCE_NAME = "tests"; + protected static final String TEST_INSTANCES_NAME = "testinstances"; + protected static final String TEST_SETS_NAME = "testsets"; + protected static final String RESULTS_RESOURCE_NAME = "Results"; + protected static final String EVENTLOG_RESOURCE_NAME = "EventLog"; + protected static final String TREND_REPORT_RESOURCE_NAME = "TrendReports"; + protected static final String TREND_REPORT_RESOURCE_SUFFIX = "data"; + protected static final String CONTENT_TYPE_XML = "application/xml"; + public static final String PC_API_XMLNS = "http://www.hp.com/PC/REST/API"; + + protected static final List validStatusCodes = Arrays.asList(SC_OK, SC_CREATED, SC_ACCEPTED, SC_NO_CONTENT); + + private String baseURL; + private String pcServer; + private String domain; + private String project; + private String webProtocol; + private String proxyScheme; + private String proxyHostName; + private int proxyPort; + private String proxyUser; + private String proxyPassword; + + private DefaultHttpClient client; + private HttpContext context; + private CookieStore cookieStore; + // private PrintStream logger; + + public PcRestProxy(String webProtocolName, String pcServerName, String almDomain, String almProject, String proxyOutURL, String proxyUser, String proxyPassword) throws PcException { + +// logger = mainLogger; + pcServer = pcServerName; + domain = almDomain; + project = almProject; + webProtocol = webProtocolName; + baseURL = String.format(PC_API_RESOURCES_TEMPLATE, webProtocol,pcServer, domain, project); + + PoolingClientConnectionManager cxMgr = new PoolingClientConnectionManager(SchemeRegistryFactory.createDefault()); + cxMgr.setMaxTotal(100); + cxMgr.setDefaultMaxPerRoute(20); + + + client = new DefaultHttpClient(cxMgr); + if (proxyOutURL != null && !proxyOutURL.isEmpty()) { + // Setting proxy + // we should get the full proxy URL from the user: http(s)://: + // PAC (proxy auto-config) or Automatic configuration script is not supported (for example our proxy: http://autocache.hpecorp.net/) + getProxyDataFromURL(proxyOutURL); + this.proxyUser = proxyUser; + this.proxyPassword = proxyPassword; + HttpHost proxy = new HttpHost(proxyHostName, proxyPort, proxyScheme); + + if (proxyUser != null && !proxyUser.isEmpty()) { + Credentials credentials = new UsernamePasswordCredentials(proxyUser, proxyPassword); + AuthScope authScope = new AuthScope(proxyHostName, proxyPort); + CredentialsProvider credsProvider = new BasicCredentialsProvider(); + client.getCredentialsProvider().setCredentials(authScope, credentials); + } + 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 { + String mainStr = ""; + if (proxyURL != null && !proxyURL.isEmpty()){ + String[] urlSplit = proxyURL.split("://"); + + proxyScheme = urlSplit[0]; + mainStr = urlSplit[1]; + if (mainStr.contains(":")){ + proxyHostName = mainStr.split(":")[0]; + proxyPort = Integer.parseInt(mainStr.split(":")[1]); + }else{ + proxyHostName = mainStr; + proxyPort = 80; + } + + + + } + } catch (Exception ex) { + throw new PcException("Error: Validating Proxy URL: " + ex + " Please add a proxy URL in this pattern: http(s)://: or leave blank"); + } + + + + } + + + public boolean authenticate(String userName, String password) throws PcException, ClientProtocolException, IOException { + String userNameAndPassword = userName + ":" + password; + String encodedCredentials = Base64Encoder.encode(userNameAndPassword.getBytes()); + HttpGet authRequest = new HttpGet(String.format(AUTHENTICATION_LOGIN_URL,webProtocol, pcServer)); + authRequest.addHeader("Authorization", String.format("Basic %s", encodedCredentials)); + executeRequest(authRequest); + return true; + } + + public PcRunResponse startRun(int testId, int testInstaceId, TimeslotDuration timeslotDuration, + String postRunAction, boolean vudsMode) throws PcException, ClientProtocolException, IOException { + // logger.println("Starting run"); + HttpPost startRunRequest = new HttpPost(String.format(baseURL + "/%s", RUNS_RESOURCE_NAME)); + startRunRequest.addHeader(RESTConstants.CONTENT_TYPE, CONTENT_TYPE_XML); + PcRunRequest runRequestData = new PcRunRequest(testId, testInstaceId, 0, timeslotDuration, postRunAction, vudsMode); + startRunRequest.setEntity(new StringEntity(runRequestData.objectToXML(), ContentType.APPLICATION_XML)); + HttpResponse response = executeRequest(startRunRequest); + String startRunResponse = IOUtils.toString(response.getEntity().getContent()); + return PcRunResponse.xmlToObject(startRunResponse); + } + + + public int createTestInstance(int testId, int testSetId) throws PcException, ClientProtocolException, IOException { + HttpPost createTestInstanceRequest = new HttpPost(String.format(baseURL + "/%s", TEST_INSTANCES_NAME)); + TestInstanceCreateRequest testInstanceCreateRequest = new TestInstanceCreateRequest(testId,testSetId); + createTestInstanceRequest.setEntity(new StringEntity(testInstanceCreateRequest.objectToXML(), ContentType.APPLICATION_XML)); + createTestInstanceRequest.addHeader(RESTConstants.CONTENT_TYPE, CONTENT_TYPE_XML); + HttpResponse response = executeRequest(createTestInstanceRequest); + String responseXml = IOUtils.toString(response.getEntity().getContent()); + int testInstanceID = 0; + try { + testInstanceID = testInstanceCreateRequest.getTestInstanceIDFromResponse(responseXml,"TestInstanceID"); + } catch (SAXException|ParserConfigurationException e) { + throw new PcException("createTestInstance exception: " + e); + } + return testInstanceID; + } + + public PcTestSets GetAllTestSets()throws IOException,PcException{ + String getTestSetsUrl = String.format(baseURL + "/%s", TEST_SETS_NAME); + HttpGet getTestSetsRequest = new HttpGet(getTestSetsUrl); + HttpResponse response = executeRequest(getTestSetsRequest); + String testSets = IOUtils.toString(response.getEntity().getContent()); + return PcTestSets.xmlToObject(testSets); + } + + public PcTestInstances getTestInstancesByTestId(int testId)throws PcException,IOException{ + String uri = String.format(baseURL + "/%s?%s=%s", TEST_INSTANCES_NAME,"query",URLEncoder.encode("{test-id[" + testId + "]}","UTF-8")); + HttpGet getFirtstTestInstanceByTestID = new HttpGet(uri); + HttpResponse response = executeRequest(getFirtstTestInstanceByTestID); + String testInstances = IOUtils.toString(response.getEntity().getContent()); + return PcTestInstances.xmlToObject(testInstances); + + } + + public boolean stopRun(int runId, String stopMode) throws PcException, ClientProtocolException, IOException { + String stopUrl = String.format(baseURL + "/%s/%s/%s", RUNS_RESOURCE_NAME, runId, stopMode); + HttpPost stopRunRequest = new HttpPost(stopUrl); + ReleaseTimeslot releaseTimesloteRequest = new ReleaseTimeslot(true, "Do Not Collate"); + stopRunRequest.addHeader(RESTConstants.CONTENT_TYPE, CONTENT_TYPE_XML); + stopRunRequest.setEntity(new StringEntity(releaseTimesloteRequest.objectToXML(), ContentType.APPLICATION_XML)); + executeRequest(stopRunRequest); + return true; + } + + public PcRunResponse getRunData(int runId) throws PcException, ClientProtocolException, IOException { + HttpGet getRunDataRequest = new HttpGet(String.format(baseURL + "/%s/%s", RUNS_RESOURCE_NAME, runId)); + HttpResponse response = executeRequest(getRunDataRequest); + String runData = IOUtils.toString(response.getEntity().getContent()); + return PcRunResponse.xmlToObject(runData); + } + + public PcTest getTestData(int testId) throws IOException, PcException { + HttpGet getTestDataRequest = new HttpGet(String.format(baseURL + "/%s/%s",TESTS_RESOURCE_NAME,testId )); + HttpResponse response = executeRequest(getTestDataRequest); + String testData = IOUtils.toString(response.getEntity().getContent()); + return PcTestData.xmlToObject(testData); + } + + public PcRunResults getRunResults(int runId) throws PcException, ClientProtocolException, IOException { + String getRunResultsUrl = String + .format(baseURL + "/%s/%s/%s", RUNS_RESOURCE_NAME, runId, RESULTS_RESOURCE_NAME); + HttpGet getRunResultsRequest = new HttpGet(getRunResultsUrl); + HttpResponse response = executeRequest(getRunResultsRequest); + String runResults = IOUtils.toString(response.getEntity().getContent()); + return PcRunResults.xmlToObject(runResults); + } + + public boolean GetRunResultData(int runId, int resultId, String localFilePath) throws PcException, ClientProtocolException, IOException { + String getRunResultDataUrl = String.format(baseURL + "/%s/%s/%s/%s/data", RUNS_RESOURCE_NAME, runId, + RESULTS_RESOURCE_NAME, resultId); + HttpGet getRunResultRequest = new HttpGet(getRunResultDataUrl); + HttpResponse response = executeRequest(getRunResultRequest); + OutputStream out = new FileOutputStream(localFilePath); + InputStream in = response.getEntity().getContent(); + IOUtils.copy(in, out); + IOUtils.closeQuietly(in); + IOUtils.closeQuietly(out); + return true; + } + + + public TrendReportTransactionDataRoot getTrendReportByXML (String trendReportId, int runId) throws PcException, ClientProtocolException, IOException { + String getTrendReportByXMLUrl = String.format(baseURL + "/%s/%s/%s", TREND_REPORT_RESOURCE_NAME, trendReportId,runId); + HttpGet getTrendReportByXMLRequest = new HttpGet(getTrendReportByXMLUrl); + HttpResponse response = executeRequest(getTrendReportByXMLRequest); + String trendReportByXML = IOUtils.toString(response.getEntity().getContent(), CharEncoding.UTF_8); + return TrendReportTransactionDataRoot.xmlToObject(trendReportByXML); + } + + + public boolean updateTrendReport(String trendReportId, TrendReportRequest trendReportRequest) throws PcException, IOException { + + String updateTrendReportUrl = String.format(baseURL + "/%s/%s", TREND_REPORT_RESOURCE_NAME, trendReportId); + HttpPost updateTrendReportRequest = new HttpPost(updateTrendReportUrl); + updateTrendReportRequest.addHeader(HttpHeaders.CONTENT_TYPE, CONTENT_TYPE_XML); + updateTrendReportRequest.setEntity(new StringEntity(trendReportRequest.objectToXML(), ContentType.APPLICATION_XML)); + executeRequest(updateTrendReportRequest); + return true; + } + + + + public InputStream getTrendingPDF(String trendReportId) throws IOException, PcException { + + String getTrendReportUrl = String.format(baseURL + "/%s/%s/%s", TREND_REPORT_RESOURCE_NAME, trendReportId,TREND_REPORT_RESOURCE_SUFFIX); + HttpGet getTrendReportRequest = new HttpGet(getTrendReportUrl); + executeRequest(getTrendReportRequest); + + HttpResponse response = executeRequest(getTrendReportRequest); + InputStream in = response.getEntity().getContent(); + + return in; + + } + + public ArrayList getTrendReportMetaData (String trendReportId) throws PcException, ClientProtocolException, IOException { + String getTrendReportMetaDataUrl = String.format(baseURL + "/%s/%s", TREND_REPORT_RESOURCE_NAME, trendReportId); + HttpGet getTrendReportMetaDataRequest = new HttpGet(getTrendReportMetaDataUrl); + HttpResponse response = executeRequest(getTrendReportMetaDataRequest); + String trendReportMetaData = IOUtils.toString(response.getEntity().getContent()); + return PcTrendReportMetaData.xmlToObject(trendReportMetaData); + } + + public PcRunEventLog getRunEventLog(int runId) throws PcException, ClientProtocolException, IOException { + String getRunEventLogUrl = String + .format(baseURL + "/%s/%s/%s", RUNS_RESOURCE_NAME, runId, EVENTLOG_RESOURCE_NAME); + HttpGet getRunEventLogRequest = new HttpGet(getRunEventLogUrl); + HttpResponse response = executeRequest(getRunEventLogRequest); + String runEventLog = IOUtils.toString(response.getEntity().getContent()); + return PcRunEventLog.xmlToObject(runEventLog); + } + + public boolean logout() throws PcException, ClientProtocolException, IOException { + HttpGet logoutRequest = new HttpGet(String.format(AUTHENTICATION_LOGOUT_URL, webProtocol,pcServer)); + executeRequest(logoutRequest); + return true; + } + + protected HttpResponse executeRequest(HttpRequestBase request) throws PcException, IOException { + + HttpResponse response = client.execute(request,context); + if (!isOk(response)){ + String message; + try { + String content = IOUtils.toString(response.getEntity().getContent()); +// logger.println("DEBUGMSG - response content: " + content); + PcErrorResponse exception = PcErrorResponse.xmlToObject(content); + message = String.format("%s Error code: %s", exception.ExceptionMessage, exception.ErrorCode); + } catch (Exception ex) { + message = response.getStatusLine().toString(); + } + throw new PcException("executeRequest exception: " + message); + } + return response; + } + + public static boolean isOk (HttpResponse response) { + return validStatusCodes.contains(response.getStatusLine().getStatusCode()); + } + + protected String getBaseURL() { + return baseURL; + } + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunEventLog.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunEventLog.java new file mode 100644 index 0000000..465baa0 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunEventLog.java @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +import java.util.ArrayList; + +public class PcRunEventLog { + + private ArrayList RecordsList; + + public PcRunEventLog() { + RecordsList = new ArrayList(); + } + + public static PcRunEventLog xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("Record" , PcRunEventLogRecord.class); + xstream.alias("EventLog" , PcRunEventLog.class); + xstream.addImplicitCollection(PcRunEventLog.class, "RecordsList"); + xstream.setClassLoader(PcRunEventLog.class.getClassLoader()); + return (PcRunEventLog)xstream.fromXML(xml); + } + + public ArrayList getRecordsList() { + return RecordsList; + } + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunEventLogRecord.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunEventLogRecord.java new file mode 100644 index 0000000..dd28231 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunEventLogRecord.java @@ -0,0 +1,72 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +public class PcRunEventLogRecord { + + private int ID; + + private String Type; + + private String Time; + + private String Name; + + private String Description; + + private String Responsible; + + public static PcRunEventLogRecord xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("Record" , PcRunEventLogRecord.class); + return (PcRunEventLogRecord)xstream.fromXML(xml); + } + + public int getID() { + return ID; + } + + public String getType() { + return Type; + } + + public String getTime() { + return Time; + } + + public String getName() { + return Name; + } + + public String getDescription() { + return Description; + } + + public String getResponsible() { + return Responsible; + } + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunRequest.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunRequest.java new file mode 100644 index 0000000..7070d1d --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunRequest.java @@ -0,0 +1,94 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +public class PcRunRequest { + + @SuppressWarnings("unused") + private String xmlns = PcRestProxy.PC_API_XMLNS; + + private int TestID; + + private int TestInstanceID; + + private int TimeslotID; + + private TimeslotDuration TimeslotDuration; + + private String PostRunAction; + + private boolean VudsMode; + + + public PcRunRequest( + int testID, + int testInstanceID, + int timeslotID, + TimeslotDuration timeslotDuration, + String postRunAction, + boolean vudsMode) { + + TestID = testID; + TestInstanceID = testInstanceID; + TimeslotID = timeslotID; + TimeslotDuration = timeslotDuration; + PostRunAction = postRunAction; + VudsMode = vudsMode; + } + + public PcRunRequest() {} + + public String objectToXML() { + XStream obj = new XStream(); + obj.alias("Run", PcRunRequest.class); + obj.alias("TimeslotDuration", TimeslotDuration.class); + obj.useAttributeFor(PcRunRequest.class, "xmlns"); + return obj.toXML(this); + } + + public int getTestID() { + return TestID; + } + + public int getTestInstanceID() { + return TestInstanceID; + } + + public int getTimeslotID() { + return TimeslotID; + } + + public TimeslotDuration getTimeslotDuration() { + return TimeslotDuration; + } + + public String getPostRunAction() { + return PostRunAction; + } + + public boolean isVudsMode() { + return VudsMode; + } +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResponse.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResponse.java new file mode 100644 index 0000000..622d0f5 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResponse.java @@ -0,0 +1,61 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +public class PcRunResponse extends PcRunRequest { + + private int ID; + + private int Duration; + + private String RunState; + + private String RunSLAStatus; + + public static PcRunResponse xmlToObject(String xml) { + XStream xstream = new XStream(); + xstream.setClassLoader(PcRunResponse.class.getClassLoader()); + xstream.alias("Run", PcRunResponse.class); + return (PcRunResponse) xstream.fromXML(xml); + + } + + public int getID() { + return ID; + } + + public int getDuration() { + return Duration; + } + + public String getRunState() { + return RunState; + } + + public String getRunSLAStatus() { + return RunSLAStatus; + } + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResult.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResult.java new file mode 100644 index 0000000..2d1545c --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResult.java @@ -0,0 +1,61 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +public class PcRunResult { + + private int ID; + + private String Name; + + private int RunID; + + private String Type; + + public static PcRunResult xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("RunResult" , PcRunResult.class); + return (PcRunResult)xstream.fromXML(xml); + } + + public int getID() { + return ID; + } + + public String getName() { + return Name; + } + + public int getRunID() { + return RunID; + } + + public String getType() { + return Type; + } + + +} \ No newline at end of file diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResults.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResults.java new file mode 100644 index 0000000..825373e --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcRunResults.java @@ -0,0 +1,50 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +import java.util.ArrayList; + +public class PcRunResults { + + private ArrayList ResultsList; + + public PcRunResults() { + ResultsList = new ArrayList(); + } + + public static PcRunResults xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("RunResult" , PcRunResult.class); + xstream.alias("RunResults" , PcRunResults.class); + xstream.addImplicitCollection(PcRunResults.class, "ResultsList"); + xstream.setClassLoader(PcRunResults.class.getClassLoader()); + return (PcRunResults)xstream.fromXML(xml); + } + + public ArrayList getResultsList() { + return ResultsList; + } +} \ No newline at end of file diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTest.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTest.java new file mode 100644 index 0000000..65c1cd0 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTest.java @@ -0,0 +1,36 @@ +package com.adm.bamboo.plugin.performancecenter.impl; + +/** + * Created by bemh on 6/5/2017. + * Partial implementation of the test xml structure + */ +public class PcTest { + + + private int testId; + private String testName; + + private int trendReportId = -1; + + + + public int getTestId() { + return testId; + } + + public String getTestName() { + return testName; + } + + public void setTrendReportId(int trendReportId) { + this.trendReportId = trendReportId; + } + + public int getTrendReportId() { + return trendReportId; + } + + public void setTestId(int testId){this.testId = testId;} + + public void setTestName(String testName){this.testName = testName;} +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestData.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestData.java new file mode 100644 index 0000000..17cdab7 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestData.java @@ -0,0 +1,68 @@ +package com.adm.bamboo.plugin.performancecenter.impl; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.io.StringReader; + +/** + * Created by bemh on 6/5/2017. + * Partial implementation of the test xml structure + */ +public class PcTestData { + + + + + static Document dom; + static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + + public static PcTest xmlToObject(String xml){ + + PcTest pcTest = new PcTest(); + + try { + DocumentBuilder db = dbf.newDocumentBuilder(); + dom = db.parse(new InputSource(new StringReader(xml))); + Element doc = dom.getDocumentElement(); + NodeList nListTestNodes = doc.getElementsByTagName("AutomaticTrending"); + if (nListTestNodes.getLength() >0 ) + { + NodeList nListChild = nListTestNodes.item(0).getChildNodes(); + for (int j=0;j < nListChild.getLength();j++) { + if (nListChild.item(j).getNodeName().equals("ReportId")){ + pcTest.setTrendReportId(Integer.parseInt(nListChild.item(j).getTextContent())); + break; + } + } + } + + nListTestNodes = doc.getElementsByTagName("ID"); + pcTest.setTestId(Integer.parseInt(nListTestNodes.item(0).getFirstChild().getNodeValue())); + + nListTestNodes = doc.getElementsByTagName("Name"); + pcTest.setTestName(nListTestNodes.item(0).getFirstChild().getNodeValue()); + + + + + }catch (ParserConfigurationException pce) { + System.out.println(pce.getMessage()); + } catch (SAXException se) { + System.out.println(se.getMessage()); + } catch (IOException ioe) { + System.err.println(ioe.getMessage()); + } + + return pcTest; + } + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestInstance.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestInstance.java new file mode 100644 index 0000000..783488e --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestInstance.java @@ -0,0 +1,31 @@ +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +/** + * Created by bemh on 6/1/2017. + */ +public class PcTestInstance { + public int TestID; + public int TestSetID; + public int TestInstanceID; + + public static PcTestInstance xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("TestInstanceID" , PcRunResult.class); + return (PcTestInstance)xstream.fromXML(xml); + } + + public int getInstanceId() { + return TestInstanceID; + } + + public int getTestId(){ + return TestID; + } + + public int getTestSetId(){ + return TestSetID; + } +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestInstances.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestInstances.java new file mode 100644 index 0000000..ca4b47c --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestInstances.java @@ -0,0 +1,32 @@ +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +import java.util.ArrayList; + +/** + * Created by bemh on 6/1/2017. + */ +public class PcTestInstances { + + + private ArrayList TestInstancesList; + + public PcTestInstances() { + TestInstancesList = new ArrayList(); + } + + public static PcTestInstances xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("TestInstance" , PcTestInstance.class); + xstream.alias("TestInstances" , PcTestInstances.class); + xstream.addImplicitCollection(PcTestInstances.class, "TestInstancesList"); + xstream.setClassLoader(PcTestInstances.class.getClassLoader()); + return (PcTestInstances)xstream.fromXML(xml); + } + + public ArrayList getTestInstancesList() { + return TestInstancesList; + } +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestSet.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestSet.java new file mode 100644 index 0000000..f537d31 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestSet.java @@ -0,0 +1,37 @@ +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +/** + * Created by bemh on 6/1/2017. + */ +public class PcTestSet { + + String TestSetName; + String TestSetComment; + int TestSetParentId; + int TestSetID; + + public static PcTestSet xmlToObject(String xml){ + XStream xstream = new XStream(); + xstream.alias("TestSetID" , PcRunResult.class); + return (PcTestSet)xstream.fromXML(xml); + } + + + public String getTestSetName(){ + return TestSetName; + } + public String getTestSetComment(){ + return TestSetComment; + } + + public int getTestSetParentId(){ + return TestSetParentId; + } + + public int getTestSetID(){ + return TestSetID; + } + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestSets.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestSets.java new file mode 100644 index 0000000..f9df7a1 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTestSets.java @@ -0,0 +1,32 @@ +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +import java.util.ArrayList; + +/** + * Created by bemh on 6/1/2017. + */ +public class PcTestSets { + + private ArrayList pcTestSetsList; + + public PcTestSets(){ + pcTestSetsList = new ArrayList(); + } + + + public static PcTestSets xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("TestSet" , PcTestSet.class); + xstream.alias("TestSets" , PcTestSets.class); + xstream.addImplicitCollection(PcTestSets.class, "pcTestSetsList"); + xstream.setClassLoader(PcTestSets.class.getClassLoader()); + return (PcTestSets)xstream.fromXML(xml); + } + + public ArrayList getPcTestSetsList() { + return pcTestSetsList; + } +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTrendReportMetaData.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTrendReportMetaData.java new file mode 100644 index 0000000..d89a43c --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/PcTrendReportMetaData.java @@ -0,0 +1,84 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; + +public class PcTrendReportMetaData { + private static ArrayList Results; + static Document dom; + static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + +// public PcTrendReportMetaData() { +// Results = new ArrayList(); +// } + + public static ArrayList xmlToObject(String xml) + { + Results = new ArrayList(); + try { + DocumentBuilder db = dbf.newDocumentBuilder(); + dom = db.parse(new InputSource(new ByteArrayInputStream(xml.getBytes("utf-8")))); + Element doc = dom.getDocumentElement(); + NodeList nListTrendedRun = doc.getElementsByTagName("TrendedRun"); + + for (int i=0;i trendReportMonitorsDataRowList; + + public TrendReportMonitorsDataRows(){ trendReportMonitorsDataRowList = new ArrayList();} + + public static TrendReportMonitorsDataRows xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("MonitorsData" , TrendReportMonitorsDataRows.class); + xstream.alias("MonitorsDataRow" , TrendReportMonitorsDataRow.class); + xstream.addImplicitCollection(TrendReportMonitorsDataRows.class, "trendReportMonitorsDataRowList"); + xstream.setClassLoader(TrendReportMonitorsDataRows.class.getClassLoader()); + return (TrendReportMonitorsDataRows)xstream.fromXML(xml); + } + + public ArrayList getTrendReportMonitorsDataRowList() { + return trendReportMonitorsDataRowList; + } + +} + + diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRegularDataRow.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRegularDataRow.java new file mode 100644 index 0000000..edae3d2 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRegularDataRow.java @@ -0,0 +1,83 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +/** + * Holds Trending Regular data + */ +public class TrendReportRegularDataRow { + + + private String PCT_TYPE; + private String PCT_NAME; + private String PCT_MINIMUM; + private String PCT_MAXIMUM; + private String PCT_AVERAGE; + private String PCT_MEDIAN; + private String PCT_STDDEVIATION; + private String PCT_SUM1; + + + public static TrendReportRegularDataRow xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("RegularDataRow" , TrendReportRegularDataRow.class); + return (TrendReportRegularDataRow)xstream.fromXML(xml); + } + + + public String getPCT_TYPE() { + return PCT_TYPE; + } + + public String getPCT_NAME() { + return PCT_NAME; + } + + public String getPCT_MINIMUM() { + return PCT_MINIMUM; + } + + public String getPCT_MAXIMUM() { + return PCT_MAXIMUM; + } + + public String getPCT_AVERAGE() { + return PCT_AVERAGE; + } + + public String getPCT_MEDIAN() { + return PCT_MEDIAN; + } + + public String getPCT_STDDEVIATION() { + return PCT_STDDEVIATION; + } + + public String getPCT_SUM1() { + return PCT_SUM1; + } + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRegularDataRows.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRegularDataRows.java new file mode 100644 index 0000000..db0bdf6 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRegularDataRows.java @@ -0,0 +1,54 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +import java.util.ArrayList; + +/** + * Holds Trending Regular + */ +public class TrendReportRegularDataRows { + + private ArrayList trendReportRegularDataRowList; + + public TrendReportRegularDataRows(){ trendReportRegularDataRowList = new ArrayList();} + + public static TrendReportRegularDataRows xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("RegularData" , TrendReportRegularDataRows.class); + xstream.alias("RegularDataRow" , TrendReportRegularDataRow.class); + xstream.addImplicitCollection(TrendReportRegularDataRows.class, "trendReportRegularDataRowList"); + xstream.setClassLoader(TrendReportRegularDataRows.class.getClassLoader()); + return (TrendReportRegularDataRows)xstream.fromXML(xml); + } + + public ArrayList getTrendReportRegularDataRowList() { + return trendReportRegularDataRowList; + } + +} + + diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRequest.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRequest.java new file mode 100644 index 0000000..a774543 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportRequest.java @@ -0,0 +1,54 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +/** + * + */ +public class TrendReportRequest { + + @SuppressWarnings("unused") + private String xmlns = PcRestProxy.PC_API_XMLNS; + + private String project; + private int runId; + private TrendedRange trandedRange; + + public TrendReportRequest(String project, int runId, TrendedRange trandedRange) { + this.project = project; + this.runId = runId; + this.trandedRange = trandedRange; + } + + public String objectToXML() { + XStream xstream = new XStream(); + xstream.useAttributeFor(TrendReportRequest.class, "xmlns"); + xstream.alias("TrendReport", TrendReportRequest.class); + xstream.aliasField("Project", TrendReportRequest.class, "project"); + xstream.aliasField("RunId", TrendReportRequest.class, "runId"); + xstream.aliasField("TrendedRange", TrendReportRequest.class, "trendedRange"); + return xstream.toXML(this); + } +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRoot.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRoot.java new file mode 100644 index 0000000..e2bc46f --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRoot.java @@ -0,0 +1,65 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +import java.util.ArrayList; +import java.util.List; + +/** + * Holds Trending Root data + */ +public class TrendReportTransactionDataRoot { + + private List trendReportRoot; + + public TrendReportTransactionDataRoot(){ + trendReportRoot = new ArrayList(); + } + + public static TrendReportTransactionDataRoot xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("Root" , TrendReportTransactionDataRoot.class); + xstream.alias("TransactionsData" , TrendReportTransactionDataRows.class); + xstream.alias("TransactionsDataRow" , TrendReportTransactionDataRow.class); + xstream.alias("MonitorsData" , TrendReportMonitorsDataRows.class); + xstream.alias("MonitorsDataRow" , TrendReportMonitorsDataRow.class); + xstream.alias("RegularData" , TrendReportRegularDataRows.class); + xstream.alias("RegularDataRow" , TrendReportRegularDataRow.class); + xstream.addImplicitCollection(TrendReportTransactionDataRoot.class, "trendReportRoot"); + xstream.addImplicitCollection(TrendReportTransactionDataRows.class, "trendReportTransactionDataRowList"); + xstream.addImplicitCollection(TrendReportMonitorsDataRows.class, "trendReportMonitorsDataRowList"); + xstream.addImplicitCollection(TrendReportRegularDataRows.class, "trendReportRegularDataRowList"); + + xstream.setClassLoader(TrendReportTransactionDataRoot.class.getClassLoader()); + return (TrendReportTransactionDataRoot)xstream.fromXML(xml); + } + + public List getTrendReportRoot() { + return trendReportRoot; + } + + +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRow.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRow.java new file mode 100644 index 0000000..3c54842 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRow.java @@ -0,0 +1,167 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +/** + * Holds Trending Transactions data + */ +public class TrendReportTransactionDataRow { + +//TRT +//Action_Transaction +//0 +//0.001 +//0.001 +//0.001 +//0 +//40 +//0.027 +//0.001118 +//0.001118 +//0.001118 +//0.0004311 +//0.0004311 +//0.0004311 +//0.0004311 +//0.0004311 +//0.0004311 +//0.0004311 +//0.0004311 +//0.0004311 + + private String PCT_TYPE; + private String PCT_NAME; + private String PCT_MINIMUM; + private String PCT_MAXIMUM; + private String PCT_AVERAGE; + private String PCT_MEDIAN; + private String PCT_STDDEVIATION; + private String PCT_COUNT1; + private String PCT_SUM1; + private String PCT_PERCENTILE_25; + private String PCT_PERCENTILE_75; + private String PCT_PERCENTILE_90; + private String PCT_PERCENTILE_91; + private String PCT_PERCENTILE_92; + private String PCT_PERCENTILE_93; + private String PCT_PERCENTILE_94; + private String PCT_PERCENTILE_95; + private String PCT_PERCENTILE_96; + private String PCT_PERCENTILE_97; + private String PCT_PERCENTILE_98; + private String PCT_PERCENTILE_99; + + public static TrendReportTransactionDataRow xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("TransactionsDataRow" , TrendReportTransactionDataRow.class); + return (TrendReportTransactionDataRow)xstream.fromXML(xml); + } + + + public String getPCT_TYPE() { + return PCT_TYPE; + } + + public String getPCT_NAME() { + return PCT_NAME; + } + + public String getPCT_MINIMUM() { + return PCT_MINIMUM; + } + + public String getPCT_MAXIMUM() { + return PCT_MAXIMUM; + } + + public String getPCT_AVERAGE() { + return PCT_AVERAGE; + } + + public String getPCT_MEDIAN() { + return PCT_MEDIAN; + } + + public String getPCT_STDDEVIATION() { + return PCT_STDDEVIATION; + } + + public String getPCT_COUNT1() { + return PCT_COUNT1; + } + + public String getPCT_SUM1() { + return PCT_SUM1; + } + + public String getPCT_PERCENTILE_25() { + return PCT_PERCENTILE_25; + } + + public String getPCT_PERCENTILE_75() { + return PCT_PERCENTILE_75; + } + + public String getPCT_PERCENTILE_90() { + return PCT_PERCENTILE_90; + } + + public String getPCT_PERCENTILE_91() { + return PCT_PERCENTILE_91; + } + + public String getPCT_PERCENTILE_92() { + return PCT_PERCENTILE_92; + } + + public String getPCT_PERCENTILE_93() { + return PCT_PERCENTILE_93; + } + + public String getPCT_PERCENTILE_94() { + return PCT_PERCENTILE_94; + } + + public String getPCT_PERCENTILE_95() { + return PCT_PERCENTILE_95; + } + + public String getPCT_PERCENTILE_96() { + return PCT_PERCENTILE_96; + } + + public String getPCT_PERCENTILE_97() { + return PCT_PERCENTILE_97; + } + + public String getPCT_PERCENTILE_98() { + return PCT_PERCENTILE_98; + } + + public String getPCT_PERCENTILE_99() { + return PCT_PERCENTILE_99; + } +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRows.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRows.java new file mode 100644 index 0000000..15207ca --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTransactionDataRows.java @@ -0,0 +1,54 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +import com.thoughtworks.xstream.XStream; + +import java.util.ArrayList; + +/** + * Holds Trending Transactions data + */ +public class TrendReportTransactionDataRows { + + private ArrayList trendReportTransactionDataRowList; + + public TrendReportTransactionDataRows(){ trendReportTransactionDataRowList = new ArrayList();} + + public static TrendReportTransactionDataRows xmlToObject(String xml) + { + XStream xstream = new XStream(); + xstream.alias("TransactionsData" , TrendReportTransactionDataRows.class); + xstream.alias("TransactionsDataRow" , TrendReportTransactionDataRow.class); + xstream.addImplicitCollection(TrendReportTransactionDataRows.class, "trendReportTransactionDataRowList"); + xstream.setClassLoader(TrendReportTransactionDataRows.class.getClassLoader()); + return (TrendReportTransactionDataRows)xstream.fromXML(xml); + } + + public ArrayList getTrendReportTransactionDataRowList() { + return trendReportTransactionDataRowList; + } + +} + + diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTypes.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTypes.java new file mode 100644 index 0000000..869fae9 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendReportTypes.java @@ -0,0 +1,62 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + +/** + * Holds Trending Types Enum + */ +public class TrendReportTypes { + + public enum DataType { + Transaction, Monitors, Regular + } + + public enum PctType { + TRT, TPS, TRS, UDP, VU, WEB + } + + public enum Measurement{ + getPCT_TYPE, + getPCT_NAME, + PCT_MINIMUM, + PCT_MAXIMUM, + PCT_AVERAGE, + PCT_MEDIAN, + PCT_STDDEVIATION, + PCT_COUNT1, + PCT_SUM1, + PCT_MACHINE, + PCT_PERCENTILE_25, + PCT_PERCENTILE_75, + PCT_PERCENTILE_90, + PCT_PERCENTILE_91, + PCT_PERCENTILE_92, + PCT_PERCENTILE_93, + PCT_PERCENTILE_94, + PCT_PERCENTILE_95, + PCT_PERCENTILE_96, + PCT_PERCENTILE_97, + PCT_PERCENTILE_98, + PCT_PERCENTILE_99 + } +} diff --git a/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendedRange.java b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendedRange.java new file mode 100644 index 0000000..e041782 --- /dev/null +++ b/src/main/java/com/adm/bamboo/plugin/performancecenter/impl/TrendedRange.java @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.adm.bamboo.plugin.performancecenter.impl; + + +public class TrendedRange { + + @SuppressWarnings("unused") + private String xmlns = PcRestProxy.PC_API_XMLNS; + private TimeInterval startTime; + private TimeInterval endTime; + + public TrendedRange(TimeInterval startTime, TimeInterval endTime) { + this.startTime = startTime; + this.endTime = endTime; + } + + public TimeInterval getStartTime() { + return startTime; + } + + public TimeInterval getEndTime() { + return endTime; + } +} diff --git a/src/main/resources/atlassian-plugin.xml b/src/main/resources/atlassian-plugin.xml index 359ba00..4887e8c 100644 --- a/src/main/resources/atlassian-plugin.xml +++ b/src/main/resources/atlassian-plugin.xml @@ -37,8 +37,7 @@ - + Run LoadRunner tests @@ -46,6 +45,12 @@ + + Execute Performance Center load test + + + +