Search in sources :

Example 1 with CIServerInfo

use of com.hp.octane.integrations.dto.general.CIServerInfo in project octane-ci-java-sdk by MicroFocus.

the class StatusInfoTest method testA.

@Test
public void testA() {
    CIProviderSummaryInfo statusInfo = dtoFactory.newDTO(CIProviderSummaryInfo.class);
    CIPluginInfo CIPluginInfo = dtoFactory.newDTO(CIPluginInfo.class).setVersion(PLUGIN_VERSION);
    CIServerInfo CIServerInfo = dtoFactory.newDTO(CIServerInfo.class).setType(CIServerTypes.JENKINS.value()).setVersion(SERVER_VERION).setInstanceId(SERVER_UUID).setInstanceIdFrom(SERVER_UUID_FROM).setSendingTime(SYNC_TIME).setUrl(INPUT_SERVER_URL);
    statusInfo.setPlugin(CIPluginInfo);
    statusInfo.setServer(CIServerInfo);
    String json = dtoFactory.dtoToJson(statusInfo);
    CIProviderSummaryInfo newStatus = dtoFactory.dtoFromJson(json, CIProviderSummaryInfo.class);
    assertNotNull(newStatus);
    assertNotNull(newStatus.getPlugin());
    assertEquals(PLUGIN_VERSION, newStatus.getPlugin().getVersion());
    assertNotNull(newStatus.getServer());
    assertEquals(CIServerTypes.JENKINS.value(), newStatus.getServer().getType());
    assertEquals(SERVER_VERION, newStatus.getServer().getVersion());
    assertEquals(SERVER_UUID, newStatus.getServer().getInstanceId());
    assertEquals(SERVER_UUID_FROM, newStatus.getServer().getInstanceIdFrom());
    assertEquals(SYNC_TIME, newStatus.getServer().getSendingTime());
    assertEquals(EXPECTED_SERVER_URL, newStatus.getServer().getUrl());
}
Also used : CIPluginInfo(com.hp.octane.integrations.dto.general.CIPluginInfo) CIServerInfo(com.hp.octane.integrations.dto.general.CIServerInfo) CIProviderSummaryInfo(com.hp.octane.integrations.dto.general.CIProviderSummaryInfo) Test(org.junit.Test)

Example 2 with CIServerInfo

use of com.hp.octane.integrations.dto.general.CIServerInfo in project octane-ci-java-sdk by MicroFocus.

the class BridgeServiceImpl method worker.

// infallible everlasting background worker
private void worker() {
    try {
        String tasksJSON = null;
        CIServerInfo serverInfo = configurer.pluginServices.getServerInfo();
        CIPluginInfo pluginInfo = configurer.pluginServices.getPluginInfo();
        String client = configurer.octaneConfiguration.getClient();
        // add log about activity once a hour
        if (hoursDifference(System.currentTimeMillis(), lastLogTime) >= 1) {
            String status = "active";
            if (configurer.octaneConfiguration.isSuspended()) {
                status = "suspended";
            } else if (!configurer.octaneConfiguration.isSdkSupported()) {
                status = "deactivated (sdk is not supported)";
            }
            logger.info(configurer.octaneConfiguration.getLocationForLog() + "task polling is " + status);
            lastLogTime = System.currentTimeMillis();
        }
        if (configurer.octaneConfiguration.isDisabled()) {
            changeServiceState(ServiceState.Disabled);
            // wait 20 sec
            CIPluginSDKUtils.doWait(20 * 1000);
        } else {
            // get tasks, wait if needed and return with task or timeout or error
            tasksJSON = getAbridgedTasks(configurer.octaneConfiguration.getInstanceId(), serverInfo.getType() == null ? CIServerTypes.UNKNOWN.value() : serverInfo.getType(), serverInfo.getUrl() == null ? "" : serverInfo.getUrl(), pluginInfo == null || pluginInfo.getVersion() == null ? "" : pluginInfo.getVersion(), client == null ? "" : client, configurer.octaneConfiguration.getImpersonatedUser() == null ? "" : configurer.octaneConfiguration.getImpersonatedUser());
        }
        // regardless of response - reconnect again to keep the light on
        if (!connectivityExecutors.isShutdown()) {
            connectivityExecutors.execute(this::worker);
        } else {
            changeServiceState(ServiceState.StopTaskPolling);
            logger.info(configurer.octaneConfiguration.getLocationForLog() + "Shutdown flag is up - stop task processing");
        }
        // now can process the received tasks - if any
        if (tasksJSON != null && !tasksJSON.isEmpty()) {
            handleTasks(tasksJSON);
        }
    } catch (Throwable t) {
        try {
            breathingOnException("getting tasks from Octane Server temporary failed", 2, t);
            if (!connectivityExecutors.isShutdown()) {
                connectivityExecutors.execute(this::worker);
            } else {
                changeServiceState(ServiceState.StopTaskPolling);
                logger.info(configurer.octaneConfiguration.getLocationForLog() + "Shutdown flag is up - stop task processing");
            }
        } catch (Throwable t2) {
            logger.error(configurer.octaneConfiguration.getLocationForLog() + "unexpected exception in BridgeServiceImpl.worker", t2);
        }
    }
}
Also used : CIPluginInfo(com.hp.octane.integrations.dto.general.CIPluginInfo) CIServerInfo(com.hp.octane.integrations.dto.general.CIServerInfo)

Example 3 with CIServerInfo

use of com.hp.octane.integrations.dto.general.CIServerInfo in project octane-ci-java-sdk by MicroFocus.

the class DTOFactoryTest method test_B.

@Test
public void test_B() {
    CIServerInfo ciServerInfo = dtoFactory.newDTO(CIServerInfo.class).setType(CIServerTypes.JENKINS.value()).setInstanceId("instance id").setInstanceIdFrom(123456789L).setSendingTime(123456789L).setUrl("http://localhost:8080").setVersion("1.2.3");
    assertEquals(CIServerTypes.JENKINS.value(), ciServerInfo.getType());
    assertEquals("instance id", ciServerInfo.getInstanceId());
    assertEquals((Long) 123456789L, ciServerInfo.getInstanceIdFrom());
    assertEquals((Long) 123456789L, ciServerInfo.getSendingTime());
    assertEquals("http://localhost:8080", ciServerInfo.getUrl());
    assertEquals("1.2.3", ciServerInfo.getVersion());
    String json = dtoFactory.dtoToJson(ciServerInfo);
}
Also used : CIServerInfo(com.hp.octane.integrations.dto.general.CIServerInfo) Test(org.junit.Test)

Example 4 with CIServerInfo

use of com.hp.octane.integrations.dto.general.CIServerInfo in project octane-ci-java-sdk by MicroFocus.

the class EventsServiceImpl method worker.

// infallible everlasting worker function
private void worker() {
    while (!eventsPushExecutor.isShutdown()) {
        if (!workerPreflight.preflight()) {
            continue;
        }
        // build events list to be sent
        List<CIEvent> eventsChunk = null;
        CIEventsList eventsSnapshot;
        try {
            eventsChunk = getEventsChunk();
            CIServerInfo serverInfo = configurer.pluginServices.getServerInfo();
            serverInfo.setInstanceId(configurer.octaneConfiguration.getInstanceId());
            eventsSnapshot = dtoFactory.newDTO(CIEventsList.class).setServer(serverInfo).setEvents(eventsChunk);
        } catch (Throwable t) {
            logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to serialize chunk of " + (eventsChunk != null ? eventsChunk.size() : "[NULL]") + " events, dropping them off (if any) and continue");
            removeEvents(eventsChunk);
            continue;
        }
        // send the data to Octane
        try {
            String correlationId = CIPluginSDKUtils.getNextCorrelationId();
            logEventsToBeSent(eventsSnapshot, correlationId);
            sendEventsData(eventsSnapshot, correlationId);
            removeEvents(eventsChunk);
            if (events.size() > 0) {
                logger.info(configurer.octaneConfiguration.getLocationForLog() + "left to send " + events.size() + " events");
            }
        } catch (RequestTimeoutException rte) {
            requestTimeoutCount++;
            lastRequestTimeoutTime = System.currentTimeMillis();
            logger.info(configurer.octaneConfiguration.getLocationForLog() + rte.getMessage());
            CIPluginSDKUtils.doWait(TEMPORARY_FAILURE_PAUSE);
        } catch (TemporaryException tqie) {
            logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to send events with temporary error, breathing " + TEMPORARY_FAILURE_PAUSE + "ms and continue", tqie);
            CIPluginSDKUtils.doWait(TEMPORARY_FAILURE_PAUSE);
        } catch (PermanentException pqie) {
            logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to send events with permanent error, dropping this chunk and continue", pqie);
            removeEvents(eventsChunk);
        } catch (Throwable t) {
            logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to send events with unexpected error, dropping this chunk and continue", t);
            removeEvents(eventsChunk);
        }
    }
}
Also used : RequestTimeoutException(com.hp.octane.integrations.exceptions.RequestTimeoutException) TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) CIEvent(com.hp.octane.integrations.dto.events.CIEvent) CIEventsList(com.hp.octane.integrations.dto.events.CIEventsList) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) CIServerInfo(com.hp.octane.integrations.dto.general.CIServerInfo)

Example 5 with CIServerInfo

use of com.hp.octane.integrations.dto.general.CIServerInfo in project octane-ci-java-sdk by MicroFocus.

the class DTOFactoryTest method test_C.

@Test
public void test_C() {
    List<CIServerInfo> coll = new ArrayList<>();
    CIServerInfo instA = dtoFactory.newDTO(CIServerInfo.class).setType(CIServerTypes.JENKINS.value()).setInstanceId("instance id A").setInstanceIdFrom(123456789L).setSendingTime(123456789L).setUrl("http://localhost:8080/A").setVersion("1.2.3");
    CIServerInfo instB = dtoFactory.newDTO(CIServerInfo.class).setType(CIServerTypes.JENKINS.value()).setInstanceId("instance id B").setInstanceIdFrom(123456789L).setSendingTime(123456789L).setUrl("http://localhost:8080/B").setVersion("1.2.4");
    CIServerInfo instC = dtoFactory.newDTO(CIServerInfo.class).setType(CIServerTypes.JENKINS.value()).setInstanceId("instance id C").setInstanceIdFrom(123456789L).setSendingTime(123456789L).setUrl("http://localhost:8080/C").setVersion("1.2.5");
    coll.add(instA);
    coll.add(instB);
    coll.add(instC);
    String json = dtoFactory.dtoCollectionToJson(coll);
    assertNotNull(json);
    CIServerInfo[] newColl = dtoFactory.dtoCollectionFromJson(json, CIServerInfo[].class);
    assertNotNull(newColl);
    assertEquals(3, newColl.length);
}
Also used : ArrayList(java.util.ArrayList) CIServerInfo(com.hp.octane.integrations.dto.general.CIServerInfo) Test(org.junit.Test)

Aggregations

CIServerInfo (com.hp.octane.integrations.dto.general.CIServerInfo)5 Test (org.junit.Test)3 CIPluginInfo (com.hp.octane.integrations.dto.general.CIPluginInfo)2 CIEvent (com.hp.octane.integrations.dto.events.CIEvent)1 CIEventsList (com.hp.octane.integrations.dto.events.CIEventsList)1 CIProviderSummaryInfo (com.hp.octane.integrations.dto.general.CIProviderSummaryInfo)1 PermanentException (com.hp.octane.integrations.exceptions.PermanentException)1 RequestTimeoutException (com.hp.octane.integrations.exceptions.RequestTimeoutException)1 TemporaryException (com.hp.octane.integrations.exceptions.TemporaryException)1 ArrayList (java.util.ArrayList)1