Skip to content

Commit

Permalink
Release 5.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
APiankouski authored Sep 23, 2024
2 parents eb1650e + ed8da17 commit 8e59081
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 123 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ on:

env:
GH_USER_NAME: github.actor
SCRIPTS_VERSION: 5.10.0
BOM_VERSION: 5.11.0
SCRIPTS_VERSION: 5.12.0
BOM_VERSION: 5.12.1

jobs:
release:
Expand Down
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ repositories {

dependencyManagement {
imports {
mavenBom(releaseMode ? 'com.epam.reportportal:commons-bom:' + getProperty('bom.version') : 'com.epam.reportportal:commons-bom:5.11.0')
mavenBom(releaseMode ? 'com.epam.reportportal:commons-bom:' + getProperty('bom.version') : 'com.epam.reportportal:commons-bom:5.12.1')
}
}

dependencies {
if (releaseMode) {
implementation 'com.epam.reportportal:commons-dao'
implementation 'com.epam.reportportal:plugin-api'
annotationProcessor 'com.epam.reportportal:plugin-api'
} else {
implementation 'com.epam.reportportal:plugin-api'
annotationProcessor 'com.epam.reportportal:plugin-api'
implementation 'com.github.reportportal:commons-dao:acf1ec7'
implementation 'com.github.reportportal:plugin-api:188792e'
annotationProcessor 'com.github.reportportal:plugin-api:188792e'
}
implementation 'com.saucelabs:saucerest:1.0.43'
implementation 'org.hibernate:hibernate-core:5.6.15.Final'

// TODO: 2.5.3+ switched to camel-case models. UI updates required
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=5.11.2
version=5.12.0
lombokVersion=1.18.34
69 changes: 42 additions & 27 deletions src/main/java/com/epam/reportportal/saucelabs/AssetsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
import static com.epam.reportportal.saucelabs.SaucelabsExtension.JOB_ID;

import com.epam.reportportal.extension.PluginCommand;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.reportportal.saucelabs.client.RestClientBuilder;
import com.epam.reportportal.saucelabs.model.SauceProperties;
import com.epam.ta.reportportal.entity.integration.Integration;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.model.ErrorType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.saucelabs.saucerest.MoshiSingleton;
import com.saucelabs.saucerest.model.jobs.JobAssets;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi;
import java.util.Map;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -40,54 +44,65 @@
@Slf4j
public class AssetsCommand implements PluginCommand<Object> {

private final RestClientBuilder restClient;
private final RestClientBuilder restClient;

public AssetsCommand(RestClientBuilder restClient) {
this.restClient = restClient;
}

@SneakyThrows
public AssetsCommand(RestClientBuilder restClient) {
this.restClient = restClient;
}

@SneakyThrows
@Override
public Object executeCommand(Integration integration, Map<String, Object> params) {
ValidationUtils.validateParams(params);
ValidationUtils.validateIntegrationParams(integration.getParams());
public Object executeCommand(Integration integration, Map<String, Object> params) {
ValidationUtils.validateParams(params);
ValidationUtils.validateIntegrationParams(integration.getParams());

SauceProperties sp = new SauceProperties(integration.getParams().getParams());
sp.setJobId((String) params.get(JOB_ID));
RestTemplate restTemplate = restClient.buildRestTemplate(sp);

try {
String url = "/rest/v1/" + sp.getUsername() + "/jobs/" + sp.getJobId() + "/assets";
String url = "/rest/v1/" + sp.getUsername() + "/jobs/" + sp.getJobId() + "/assets";
String jobAssets = restTemplate.getForObject(url, String.class);
JSONObject response = new JSONObject(jobAssets);

JSONObject response = new JSONObject(jobAssets);
response.put("assetsPrefix",
sp.getDatacenter().apiServer + "rest/v1/" + sp.getUsername() + "/jobs/" + sp.getJobId()
+ "/assets");
return new ObjectMapper().readValue(response.toString(), Object.class);
return new ObjectMapper().readValue(response.toString(), Object.class);

} catch (HttpClientErrorException httpException) {
if (httpException.getStatusCode().is4xxClientError()) {
// TODO: handle RD endpoint in a separate plugin command. UI updates required
//String url = sp.getDatacenter().apiServer + "v1/rdc/jobs/" + sp.getJobId();
//String url = sp.getDatacenter().apiServer + "v1/rdc/jobs/" + sp.getJobId();
//DeviceJob deviceJob = restTemplate.getForObject(url, DeviceJob.class);

JSONObject response = new JSONObject();
JSONObject response = new JSONObject();
response.put("assetsPrefix",
String.format("%sv1/rdc/jobs/%s/", sp.getDatacenter().apiServer, sp.getJobId()));
response.put("screenshots", new JSONArray());
response.put("sauce-log",
String.format("%sv1/rdc/jobs/%s/deviceLogs", sp.getDatacenter().apiServer,
String.format("%sv1/rdc/jobs/%s/", sp.getDatacenter().apiServer, sp.getJobId()));
response.put("screenshots", new JSONArray());
response.put("sauce-log",
String.format("%sv1/rdc/jobs/%s/deviceLogs", sp.getDatacenter().apiServer,
sp.getJobId()));
return new ObjectMapper().readValue(response.toString(), Object.class);

} else {
throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, StringUtils.normalizeSpace("Failed to retrieve job assets"));
} else {
throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION,
StringUtils.normalizeSpace("Failed to retrieve job assets"));
}
}
}
}
}

@Override
public String getName() {
return "assets";
}


public String toJson(JobAssets jobAssets) {
Moshi moshi = MoshiSingleton.getInstance();

@Override
public String getName() {
return "assets";
}
JsonAdapter<JobAssets> jsonAdapter = moshi.adapter(JobAssets.class).nonNull();
return jsonAdapter.toJson(jobAssets);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import static com.epam.reportportal.saucelabs.ValidationUtils.validateParams;

import com.epam.reportportal.extension.PluginCommand;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.entity.integration.Integration;
import com.epam.ta.reportportal.exception.ReportPortalException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;
Expand All @@ -22,38 +22,36 @@
*/
public class GenerateAuthTokenCommand implements PluginCommand<Object> {

private final BasicTextEncryptor textEncryptor;
private final BasicTextEncryptor textEncryptor;

public GenerateAuthTokenCommand(BasicTextEncryptor textEncryptor) {
this.textEncryptor = textEncryptor;
}
public GenerateAuthTokenCommand(BasicTextEncryptor textEncryptor) {
this.textEncryptor = textEncryptor;
}

@Override
public Object executeCommand(Integration integration, Map params) {
try {
validateParams(params);
@Override
public Object executeCommand(Integration integration, Map params) {
try {
validateParams(params);
validateIntegrationParams(integration.getParams());

String username = USERNAME.getParam(integration.getParams())
;
String accessToken = textEncryptor.decrypt(ACCESS_TOKEN.getParam(integration.getParams())

);

SecretKeySpec keySpec = new SecretKeySpec((username + ":" + accessToken).getBytes(StandardCharsets.UTF_8), "HmacMD5");
Mac mac = Mac.getInstance("HmacMD5");
mac.init(keySpec);
return Collections.singletonMap(
"token",
Hex.encodeHexString(mac.doFinal(params.get(JOB_ID).toString().getBytes(StandardCharsets.UTF_8)))
);
} catch (Exception e) {
throw new ReportPortalException(e.getMessage());
}
}

@Override
public String getName() {
return "token";
}
String username = USERNAME.getParam(integration.getParams());
String accessToken = textEncryptor.decrypt(ACCESS_TOKEN.getParam(integration.getParams()));

SecretKeySpec keySpec =
new SecretKeySpec((username + ":" + accessToken).getBytes(StandardCharsets.UTF_8),
"HmacMD5"
);
Mac mac = Mac.getInstance("HmacMD5");
mac.init(keySpec);
return Collections.singletonMap("token", Hex.encodeHexString(
mac.doFinal(params.get(JOB_ID).toString().getBytes(StandardCharsets.UTF_8))));
} catch (Exception e) {
throw new ReportPortalException(e.getMessage());
}
}

@Override
public String getName() {
return "token";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import static com.epam.reportportal.saucelabs.SaucelabsExtension.JOB_ID;

import com.epam.reportportal.extension.PluginCommand;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.reportportal.saucelabs.client.RestClientBuilder;
import com.epam.reportportal.saucelabs.model.SauceProperties;
import com.epam.ta.reportportal.entity.integration.Integration;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.model.ErrorType;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -46,15 +46,19 @@ public GetLogsCommand(RestClientBuilder restClient) {
public Object executeCommand(Integration integration, Map<String, Object> params) {
ValidationUtils.validateParams(params);
ValidationUtils.validateIntegrationParams(integration.getParams());

SauceProperties sp = new SauceProperties(integration.getParams().getParams());
sp.setJobId((String) params.get(JOB_ID));

return getWebDriverLogs(restClient.buildRestTemplate(sp), sp);
}


private Object getWebDriverLogs(RestTemplate restTemplate, SauceProperties sp) {
try {
String url = getJobAssetsUrl(sp) + "/log.json";
return restTemplate.getForObject(url, Object.class);

} catch (HttpClientErrorException httpException) {

if (httpException.getStatusCode().is4xxClientError()) {
Expand All @@ -67,6 +71,7 @@ private Object getWebDriverLogs(RestTemplate restTemplate, SauceProperties sp) {
}
}


// TODO: handle RD endpoint in a separate plugin command. UI updates required
private Object getRealDeviceLogs(RestTemplate restTemplate, SauceProperties sp) {
String url = "/v1/rdc/jobs/" + sp.getJobId() + "/deviceLogs";
Expand All @@ -87,4 +92,5 @@ private String getJobAssetsUrl(SauceProperties sp) {
.append("/assets")
.toString();
}

}
58 changes: 30 additions & 28 deletions src/main/java/com/epam/reportportal/saucelabs/JobInfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import static com.epam.reportportal.saucelabs.utils.OldDatacenterResolver.resolveDatacenterDeprecatedName;

import com.epam.reportportal.extension.PluginCommand;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.reportportal.saucelabs.utils.JsonUtils;
import com.epam.ta.reportportal.entity.integration.Integration;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.model.ErrorType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.saucelabs.saucerest.SauceException;
import com.saucelabs.saucerest.SauceREST;
Expand All @@ -41,47 +41,49 @@
@Slf4j
public class JobInfoCommand implements PluginCommand<Object> {

private final SauceRestClient sauceRestClient;
private final SauceRestClient sauceRestClient;

public JobInfoCommand(SauceRestClient sauceRestClient) {
this.sauceRestClient = sauceRestClient;
}
public JobInfoCommand(SauceRestClient sauceRestClient) {
this.sauceRestClient = sauceRestClient;
}

@Override
public Object executeCommand(Integration integration, Map params) {
ValidationUtils.validateParams(params);
String datacenter = (String) params.get(DATA_CENTER.getName());

@Override
public Object executeCommand(Integration integration, Map params) {
ValidationUtils.validateParams(params);
String datacenter = (String) params.get(DATA_CENTER.getName());
SauceREST sauce =
SauceREST sauce =
sauceRestClient.buildSauceClient(integration, resolveDatacenterDeprecatedName(datacenter));
String jobId = (String) params.get(JOB_ID);
try {
return findJobById(sauce,jobId);
} catch (IOException e) {
throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION,
StringUtils.normalizeSpace(e.getMessage()));
String jobId = (String) params.get(JOB_ID);

try {
return findJobById(sauce, jobId);
} catch (IOException e) {
throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION,
StringUtils.normalizeSpace(e.getMessage()));
}
}

private Object findJobById(SauceREST sauce, String jobId)
throws IOException {
throws IOException {
Object response;
try {
// find job if exists
Job jobInfo = sauce.getJobsEndpoint().getJobDetails(jobId);
// find job if exists
Job jobInfo = sauce.getJobsEndpoint().getJobDetails(jobId);
response = new ObjectMapper().readValue(jobInfo.toJson(), Object.class);
} catch (SauceException jobException) {
} catch (SauceException jobException) {
// If job not exists find real device job
// TODO: introduce separate plugin command. UI updates required
DeviceJob dj = sauce.getRealDevicesEndpoint().getSpecificDeviceJob(jobId);
JsonUtils.toJson(dj, DeviceJob.class);
response = new ObjectMapper()
response = new ObjectMapper()
.readValue(JsonUtils.toJson(dj, DeviceJob.class), Object.class);
}
return response;
}
return response;
}

@Override
public String getName() {
return "jobInfo";
}
@Override
public String getName() {
return "jobInfo";
}
}
Loading

0 comments on commit 8e59081

Please sign in to comment.