use of com.hp.octane.integrations.OctaneConfiguration in project octane-ci-java-sdk by MicroFocus.
the class TaskingServiceTests method setupClient.
@BeforeClass
public static void setupClient() {
String inId = UUID.randomUUID().toString();
String sspId = UUID.randomUUID().toString();
OctaneConfiguration configuration = new OctaneConfigurationIntern(inId, OctaneSPEndpointSimulator.getSimulatorUrl(), sspId);
client = OctaneSDK.addClient(configuration, TaskingTestPluginServicesTest.class);
}
use of com.hp.octane.integrations.OctaneConfiguration in project octane-ci-java-sdk by MicroFocus.
the class TaskingServiceE2ETests method setupEnvironment.
@BeforeClass
public static void setupEnvironment() {
// setup Octane simulator
OctaneSPEndpointSimulator octaneSPEndpointSimulator = setupOctaneEPSimulator(sspId);
Assert.assertNotNull(octaneSPEndpointSimulator);
// setup Octane client
OctaneConfiguration configuration = new OctaneConfigurationIntern(inId, OctaneSPEndpointSimulator.getSimulatorUrl(), sspId);
client = OctaneSDK.addClient(configuration, TaskingTestPluginServicesTest.class);
}
use of com.hp.octane.integrations.OctaneConfiguration in project octane-ci-java-sdk by MicroFocus.
the class LogsServiceImpl method pushBuildLog.
private void pushBuildLog(String serverId, BuildLogQueueItem queueItem) {
OctaneConfiguration octaneConfiguration = configurer.octaneConfiguration;
String encodedServerId = CIPluginSDKUtils.urlEncodePathParam(serverId);
String encodedBuildId = CIPluginSDKUtils.urlEncodePathParam(queueItem.buildId);
boolean base64 = isEncodeBase64();
String encodedJobId = base64 ? CIPluginSDKUtils.urlEncodeBase64(queueItem.jobId) : CIPluginSDKUtils.urlEncodePathParam(queueItem.jobId);
String encodedRootJobId = base64 ? CIPluginSDKUtils.urlEncodeBase64(queueItem.rootJobId) : CIPluginSDKUtils.urlEncodeQueryParam(queueItem.rootJobId);
// preflight
String[] workspaceIDs = preflightRequest(octaneConfiguration, encodedServerId, encodedJobId, encodedRootJobId, base64);
if (workspaceIDs.length == 0) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "log of " + queueItem + ", no interested workspace is found");
return;
} else {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "log of " + queueItem + ", found " + workspaceIDs.length + " interested workspace/s");
}
// submit log for each workspace returned by the 'preflight' API
// [YG] TODO: the code below should and will be refactored to a simpler state once Octane's APIs will be adjusted
InputStream log;
OctaneRequest request;
OctaneResponse response;
for (String workspaceId : workspaceIDs) {
String url = octaneConfiguration.getUrl() + RestService.SHARED_SPACE_INTERNAL_API_PATH_PART + octaneConfiguration.getSharedSpace() + "/workspaces/" + workspaceId + RestService.ANALYTICS_CI_PATH_PART + encodedServerId + "/" + encodedJobId + "/" + encodedBuildId + "/logs";
if (base64) {
url = CIPluginSDKUtils.addParameterEncode64ToUrl(url);
}
String correlationId = CIPluginSDKUtils.getNextCorrelationId();
Map<String, String> headers = new HashMap<>();
headers.put(CORRELATION_ID_HEADER, correlationId);
request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.POST).setHeaders(headers).setUrl(url);
try {
log = configurer.pluginServices.getBuildLog(queueItem.jobId, queueItem.buildId);
if (log == null) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "no log for " + queueItem + " found, abandoning");
break;
}
request.setBody(log);
response = restService.obtainOctaneRestClient().execute(request);
if (response.getStatus() == HttpStatus.SC_OK) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "successfully pushed log of " + queueItem + " to WS " + workspaceId + ", correlation Id = " + correlationId);
} else {
logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to push log of " + queueItem + " to WS " + workspaceId + ", status: " + response.getStatus() + ", correlation Id = " + correlationId);
}
} catch (IOException ioe) {
logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to push log of " + queueItem + " to WS " + workspaceId + ", breathing " + TEMPORARY_ERROR_BREATHE_INTERVAL + "ms and retrying one more time due to IOException", ioe);
CIPluginSDKUtils.doWait(TEMPORARY_ERROR_BREATHE_INTERVAL);
log = configurer.pluginServices.getBuildLog(queueItem.jobId, queueItem.buildId);
if (log == null) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "no log for " + queueItem + " found, abandoning");
break;
}
request.setBody(log);
try {
response = restService.obtainOctaneRestClient().execute(request);
if (response.getStatus() == HttpStatus.SC_OK) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "successfully pushed log of " + queueItem + " to WS " + workspaceId);
} else {
logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to push log of " + queueItem + " to WS " + workspaceId + ", status: " + response.getStatus());
}
} catch (IOException ioem) {
logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to push log of " + queueItem + " to WS " + workspaceId + " for the second time, abandoning", ioem);
}
}
}
}
use of com.hp.octane.integrations.OctaneConfiguration in project octane-ci-java-sdk by MicroFocus.
the class TestsServiceNegativeTests method setupClient.
@BeforeClass
public static void setupClient() {
String inId = UUID.randomUUID().toString();
String sspId = UUID.randomUUID().toString();
OctaneConfiguration configuration = new OctaneConfigurationIntern(inId, OctaneSPEndpointSimulator.getSimulatorUrl(), sspId);
client = OctaneSDK.addClient(configuration, TestsServicePluginServicesTest.class);
}
use of com.hp.octane.integrations.OctaneConfiguration in project octane-ci-java-sdk by MicroFocus.
the class OctaneSDKBasicFunctionalityTest method testE2EFunctional.
@Test(timeout = 60000)
public void testE2EFunctional() throws ExecutionException, InterruptedException {
Map<String, OctaneSPEndpointSimulator> simulators = null;
Map<String, List<CIEventsList>> eventsCollectors = new LinkedHashMap<>();
Map<String, List<TestsResult>> testResultsCollectors = new LinkedHashMap<>();
Map<String, List<String>> logsCollectors = new LinkedHashMap<>();
Map<String, List<String>> coverageCollectors = new LinkedHashMap<>();
OctaneClient clientA = null;
try {
String spIdA = UUID.randomUUID().toString();
String spIdB = UUID.randomUUID().toString();
String clientAInstanceId = UUID.randomUUID().toString();
String clientBInstanceId = UUID.randomUUID().toString();
// init 2 shared space endpoints simulators
simulators = initSPEPSimulators(Stream.of(spIdA, spIdB).collect(Collectors.toSet()), eventsCollectors, testResultsCollectors, logsCollectors, coverageCollectors);
//
// I
// add one client and verify it works okay
//
System.out.println("Scenario 1 - add one client and verify it works okay");
clientA = OctaneSDK.addClient(new OctaneConfigurationBasicFunctionalityTest(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA, "client_SP_A", "secret_SP_A"), PluginServicesBasicFunctionalityTest.class);
clientA.getConfigurationService().addToOctaneRootsCache("job-a");
clientA.getConfigurationService().getOctaneConnectivityStatus();
simulateEventsCycleAllClients();
simulatePushTestResultsCycleAllClients();
simulatePushLogsCycleAllClients();
simulatePushCoverageAllClients();
// validate events
GeneralTestUtils.waitAtMostFor(10000, () -> {
if (eventsCollectors.containsKey(spIdA) && eventsCollectors.get(spIdA).stream().mapToInt(cil -> cil.getEvents().size()).sum() == 3) {
eventsCollectors.get(spIdA).forEach(cil -> {
Assert.assertNotNull(cil);
Assert.assertNotNull(cil.getServer());
Assert.assertEquals(clientAInstanceId, cil.getServer().getInstanceId());
Assert.assertEquals("custom", cil.getServer().getType());
Assert.assertEquals("1.1.1", cil.getServer().getVersion());
Assert.assertEquals("http://localhost:9999", cil.getServer().getUrl());
});
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate tests
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (testResultsCollectors.containsKey(spIdA) && testResultsCollectors.get(spIdA).size() == 1) {
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate logs
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (logsCollectors.containsKey(spIdA) && logsCollectors.get(spIdA).size() == 1) {
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate coverage
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (coverageCollectors.containsKey(spIdA) && coverageCollectors.get(spIdA).size() == 2) {
// TODO: add deeper verification
return true;
} else {
return null;
}
});
//
// II
// add one more client and verify they are both works okay
//
System.out.println("Scenario 2 - add one more client and verify they are both works okay");
OctaneClient clientB = OctaneSDK.addClient(new OctaneConfigurationBasicFunctionalityTest(clientBInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdB, "client_SP_B", "secret_SP_B"), PluginServicesBasicFunctionalityTest.class);
clientB.getConfigurationService().addToOctaneRootsCache("job-a");
clientB.getConfigurationService().getOctaneConnectivityStatus();
eventsCollectors.get(spIdA).clear();
testResultsCollectors.get(spIdA).clear();
logsCollectors.get(spIdA).clear();
coverageCollectors.get(spIdA).clear();
simulateEventsCycleAllClients();
simulatePushTestResultsCycleAllClients();
simulatePushLogsCycleAllClients();
simulatePushCoverageAllClients();
// validate events
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (eventsCollectors.containsKey(spIdA) && eventsCollectors.get(spIdA).stream().mapToInt(cil -> cil.getEvents().size()).sum() == 3 && eventsCollectors.containsKey(spIdB) && eventsCollectors.get(spIdA).stream().mapToInt(cil -> cil.getEvents().size()).sum() == 3) {
// client A
eventsCollectors.get(spIdA).forEach(cil -> {
Assert.assertNotNull(cil);
Assert.assertNotNull(cil.getServer());
Assert.assertEquals(clientAInstanceId, cil.getServer().getInstanceId());
Assert.assertEquals("custom", cil.getServer().getType());
Assert.assertEquals("1.1.1", cil.getServer().getVersion());
Assert.assertEquals("http://localhost:9999", cil.getServer().getUrl());
});
// client B
eventsCollectors.get(spIdB).forEach(cil -> {
Assert.assertNotNull(cil);
Assert.assertNotNull(cil.getServer());
Assert.assertEquals(clientBInstanceId, cil.getServer().getInstanceId());
Assert.assertEquals("custom", cil.getServer().getType());
Assert.assertEquals("1.1.1", cil.getServer().getVersion());
Assert.assertEquals("http://localhost:9999", cil.getServer().getUrl());
});
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate tests
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (testResultsCollectors.containsKey(spIdA) && testResultsCollectors.get(spIdA).size() == 1 && testResultsCollectors.containsKey(spIdB) && testResultsCollectors.get(spIdB).size() == 1) {
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate logs
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (logsCollectors.containsKey(spIdA) && logsCollectors.get(spIdA).size() == 1 && logsCollectors.containsKey(spIdB) && logsCollectors.get(spIdB).size() == 1) {
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate coverages
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (coverageCollectors.containsKey(spIdA) && coverageCollectors.get(spIdA).size() == 2 && coverageCollectors.containsKey(spIdB) && coverageCollectors.get(spIdB).size() == 2) {
// TODO: add deeper verification
return true;
} else {
return null;
}
});
//
// III
// remove one client and verify it is shut indeed and the second continue to work okay
//
System.out.println("Scenario 3 - remove one client and verify it is shut indeed and the second continue to work okay");
OctaneSDK.removeClient(clientA);
eventsCollectors.get(spIdA).clear();
eventsCollectors.get(spIdB).clear();
testResultsCollectors.get(spIdA).clear();
testResultsCollectors.get(spIdB).clear();
logsCollectors.get(spIdA).clear();
logsCollectors.get(spIdB).clear();
coverageCollectors.get(spIdA).clear();
coverageCollectors.get(spIdB).clear();
simulateEventsCycleAllClients();
simulatePushTestResultsCycleAllClients();
simulatePushLogsCycleAllClients();
simulatePushCoverageAllClients();
// validate events
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (eventsCollectors.containsKey(spIdB) && eventsCollectors.get(spIdB).stream().mapToInt(cil -> cil.getEvents().size()).sum() == 3) {
Assert.assertTrue(eventsCollectors.get(spIdA).isEmpty());
eventsCollectors.get(spIdB).forEach(cil -> {
Assert.assertNotNull(cil);
Assert.assertNotNull(cil.getServer());
Assert.assertEquals(clientBInstanceId, cil.getServer().getInstanceId());
Assert.assertEquals("custom", cil.getServer().getType());
Assert.assertEquals("1.1.1", cil.getServer().getVersion());
Assert.assertEquals("http://localhost:9999", cil.getServer().getUrl());
});
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate tests
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (testResultsCollectors.containsKey(spIdB) && testResultsCollectors.get(spIdB).size() == 1) {
Assert.assertTrue(testResultsCollectors.get(spIdA).isEmpty());
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate logs
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (logsCollectors.containsKey(spIdB) && logsCollectors.get(spIdB).size() == 1) {
Assert.assertTrue(logsCollectors.get(spIdA).isEmpty());
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate coverages
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (coverageCollectors.containsKey(spIdB) && coverageCollectors.get(spIdB).size() == 2) {
Assert.assertTrue(coverageCollectors.get(spIdA).isEmpty());
// TODO: add deeper verification
return true;
} else {
return null;
}
});
//
// IV
// remove second client and ensure no interactions anymore
//
System.out.println("Scenario 4 - remove second client and ensure no interactions anymore");
OctaneSDK.removeClient(clientB);
eventsCollectors.get(spIdB).clear();
testResultsCollectors.get(spIdB).clear();
logsCollectors.get(spIdB).clear();
coverageCollectors.get(spIdB).clear();
// events, tests, logs
simulateEventsCycleAllClients();
simulatePushTestResultsCycleAllClients();
simulatePushLogsCycleAllClients();
simulatePushCoverageAllClients();
CIPluginSDKUtils.doWait(4000);
Assert.assertTrue(eventsCollectors.get(spIdA).isEmpty());
Assert.assertTrue(eventsCollectors.get(spIdB).isEmpty());
Assert.assertTrue(testResultsCollectors.get(spIdA).isEmpty());
Assert.assertTrue(testResultsCollectors.get(spIdB).isEmpty());
Assert.assertTrue(logsCollectors.get(spIdA).isEmpty());
Assert.assertTrue(logsCollectors.get(spIdB).isEmpty());
Assert.assertTrue(coverageCollectors.get(spIdA).isEmpty());
Assert.assertTrue(coverageCollectors.get(spIdB).isEmpty());
//
// V
// add clientA in with deactivated Mode
//
System.out.println("Scenario 5 - add clientA in with deactivated Mode");
clientA = OctaneSDK.addClient(new OctaneConfigurationBasicFunctionalityTest(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA, "client_SP_A", "secret_SP_A"), PluginServicesBasicFunctionalityTest.class);
clientA.getConfigurationService().getConfiguration().setSuspended(true);
clientA.getConfigurationService().getOctaneConnectivityStatus();
simulateEventsCycleAllClients();
simulatePushTestResultsCycleAllClients();
simulatePushLogsCycleAllClients();
simulatePushCoverageAllClients();
CIPluginSDKUtils.doWait(4000);
Assert.assertTrue(eventsCollectors.get(spIdA).isEmpty());
Assert.assertTrue(eventsCollectors.get(spIdB).isEmpty());
Assert.assertTrue(testResultsCollectors.get(spIdA).isEmpty());
Assert.assertTrue(testResultsCollectors.get(spIdB).isEmpty());
Assert.assertTrue(logsCollectors.get(spIdA).isEmpty());
Assert.assertTrue(logsCollectors.get(spIdB).isEmpty());
Assert.assertTrue(coverageCollectors.get(spIdA).isEmpty());
Assert.assertTrue(coverageCollectors.get(spIdB).isEmpty());
OctaneSDK.removeClient(clientA);
//
// 6
// add client with parameter OCTANE_ROOTS_CACHE_ALLOWED=true with no pipeline root
//
System.out.println("Scenario 6 - add client with parameter OCTANE_ROOTS_CACHE_ALLOWED=true with no pipeline root");
OctaneConfiguration tempConf = new OctaneConfigurationBasicFunctionalityTest(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA, "client_SP_A", "secret_SP_A");
ConfigurationParameterFactory.addParameter(tempConf, "OCTANE_ROOTS_CACHE_ALLOWED", "true");
clientA = OctaneSDK.addClient(tempConf, PluginServicesBasicFunctionalityTest.class);
clientA.getConfigurationService().getOctaneConnectivityStatus();
simulateEventsCycleAllClients();
simulatePushTestResultsCycleAllClients();
simulatePushLogsCycleAllClients();
simulatePushCoverageAllClients();
CIPluginSDKUtils.doWait(4000);
Assert.assertTrue(eventsCollectors.get(spIdA).isEmpty());
Assert.assertTrue(eventsCollectors.get(spIdB).isEmpty());
Assert.assertTrue(testResultsCollectors.get(spIdA).isEmpty());
Assert.assertTrue(testResultsCollectors.get(spIdB).isEmpty());
Assert.assertTrue(logsCollectors.get(spIdA).isEmpty());
Assert.assertTrue(logsCollectors.get(spIdB).isEmpty());
Assert.assertTrue(coverageCollectors.get(spIdA).isEmpty());
Assert.assertTrue(coverageCollectors.get(spIdB).isEmpty());
//
// 7
// add client with parameter OCTANE_ROOTS_CACHE_ALLOWED=true with one root
//
System.out.println("Scenario 7 - add client with parameter OCTANE_ROOTS_CACHE_ALLOWED=true with one root");
clientA.getConfigurationService().addToOctaneRootsCache("job-a");
simulateEventsCycleAllClients();
simulatePushTestResultsCycleAllClients();
simulatePushLogsCycleAllClients();
simulatePushCoverageAllClients();
CIPluginSDKUtils.doWait(4000);
// validate events
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (eventsCollectors.containsKey(spIdA) && eventsCollectors.get(spIdA).stream().mapToInt(cil -> cil.getEvents().size()).sum() == 3) {
eventsCollectors.get(spIdA).forEach(cil -> {
Assert.assertNotNull(cil);
Assert.assertNotNull(cil.getServer());
Assert.assertEquals(clientAInstanceId, cil.getServer().getInstanceId());
Assert.assertEquals("custom", cil.getServer().getType());
Assert.assertEquals("1.1.1", cil.getServer().getVersion());
Assert.assertEquals("http://localhost:9999", cil.getServer().getUrl());
});
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate tests
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (testResultsCollectors.containsKey(spIdA) && testResultsCollectors.get(spIdA).size() == 1) {
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate logs
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (logsCollectors.containsKey(spIdA) && logsCollectors.get(spIdA).size() == 1) {
// TODO: add deeper verification
return true;
} else {
return null;
}
});
// validate coverage
GeneralTestUtils.waitAtMostFor(5000, () -> {
if (coverageCollectors.containsKey(spIdA) && coverageCollectors.get(spIdA).size() == 2) {
// TODO: add deeper verification
return true;
} else {
return null;
}
});
} finally {
// remove clients
OctaneSDK.getClients().forEach(OctaneSDK::removeClient);
// remove simulators
if (simulators != null)
removeSPEPSimulators(simulators.values());
}
}
Aggregations