-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPMRPP-94504 improve saucelabs plugin
- Loading branch information
Showing
20 changed files
with
288 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
version=5.11.0 | ||
lombokVersion=1.18.34 | ||
testsEnabled=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,41 +13,42 @@ | |
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.epam.reportportal.saucelabs; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.function.Supplier; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Ivan Budayeu</a> | ||
*/ | ||
public class MemoizingSupplier<T> implements Supplier<T> { | ||
|
||
private final Supplier<T> delegate; | ||
|
||
private AtomicBoolean initialized = new AtomicBoolean(false); | ||
|
||
private T value; | ||
|
||
public MemoizingSupplier(Supplier<T> delegate) { | ||
this.delegate = checkNotNull(delegate); | ||
} | ||
|
||
@Override | ||
public T get() { | ||
if (!initialized.get()) { | ||
synchronized (this) { | ||
if (!initialized.get()) { | ||
T t = delegate.get(); | ||
value = t; | ||
initialized.set(true); | ||
return t; | ||
} | ||
} | ||
} | ||
return value; | ||
} | ||
private final Supplier<T> delegate; | ||
|
||
private AtomicBoolean initialized = new AtomicBoolean(false); | ||
|
||
private T value; | ||
|
||
public MemoizingSupplier(Supplier<T> delegate) { | ||
this.delegate = checkNotNull(delegate); | ||
} | ||
|
||
@Override | ||
public T get() { | ||
if (!initialized.get()) { | ||
synchronized (this) { | ||
if (!initialized.get()) { | ||
T t = delegate.get(); | ||
value = t; | ||
initialized.set(true); | ||
return t; | ||
} | ||
} | ||
} | ||
return value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/main/java/com/epam/reportportal/saucelabs/command/GenerateAuthTokenCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,21 +16,25 @@ | |
|
||
package com.epam.reportportal.saucelabs.command; | ||
|
||
|
||
import static com.epam.reportportal.saucelabs.model.Constants.GET_VDC_JOB_ASSETS; | ||
import static com.epam.reportportal.saucelabs.model.Constants.GET_VDC_JOB_LOGS; | ||
import static com.epam.reportportal.saucelabs.model.Constants.JOB_ID; | ||
import static com.epam.reportportal.saucelabs.model.Constants.LOG_URL; | ||
|
||
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.ValidationUtils; | ||
import com.epam.reportportal.saucelabs.client.RestClientBuilder; | ||
import com.epam.reportportal.saucelabs.model.SauceProperties; | ||
import com.epam.reportportal.saucelabs.model.IntegrationProperties; | ||
import com.epam.reportportal.saucelabs.utils.ValidationUtils; | ||
import com.epam.ta.reportportal.entity.integration.Integration; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Pavel Bortnik</a> | ||
|
@@ -49,12 +53,21 @@ public Object executeCommand(Integration integration, Map<String, Object> params | |
ValidationUtils.validateJobId(params); | ||
ValidationUtils.validateIntegrationParams(integration.getParams()); | ||
|
||
SauceProperties sp = new SauceProperties(integration.getParams().getParams()); | ||
IntegrationProperties sp = new IntegrationProperties(integration.getParams().getParams()); | ||
sp.setJobId((String) params.get(JOB_ID)); | ||
RestTemplate restTemplate = restClient.buildRestTemplate(sp); | ||
|
||
String logsUrl = String.format(GET_VDC_JOB_LOGS, sp.getUsername(), sp.getJobId()); | ||
try { | ||
return restClient.buildRestTemplate(sp).getForObject(logsUrl, Object.class); | ||
// check if logs exist | ||
String assetsUrl = String.format(GET_VDC_JOB_ASSETS, sp.getUsername(), sp.getJobId()); | ||
String jobAssets = restTemplate.getForObject(assetsUrl, String.class); | ||
JsonObject jsonElement = (JsonObject) JsonParser.parseString(jobAssets); | ||
if (jsonElement.get(LOG_URL) == null) { | ||
throw new ReportPortalException(ErrorType.NOT_FOUND, "Logs"); | ||
} | ||
|
||
String logsUrl = String.format(GET_VDC_JOB_LOGS, sp.getUsername(), sp.getJobId()); | ||
return restTemplate.getForObject(logsUrl, Object.class); | ||
} catch (HttpClientErrorException httpException) { | ||
throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, | ||
StringUtils.normalizeSpace("Failed to retrieve job assets")); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.