Search in sources :

Example 1 with CIPluginInfo

use of com.hp.octane.integrations.dto.general.CIPluginInfo 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 CIPluginInfo

use of com.hp.octane.integrations.dto.general.CIPluginInfo 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 CIPluginInfo

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

the class DTOFactoryTest method test_A.

@Test
public void test_A() {
    CIPluginInfo CIPluginInfo = dtoFactory.newDTO(CIPluginInfo.class);
    assertNotNull(CIPluginInfo);
    assertNull(CIPluginInfo.getVersion());
    CIPluginInfo newRef = CIPluginInfo.setVersion("1.2.3");
    assertNotNull(newRef);
    assertEquals(newRef, CIPluginInfo);
    assertEquals("1.2.3", CIPluginInfo.getVersion());
    assertEquals("1.2.3", newRef.getVersion());
    String jsonA = dtoFactory.dtoToJson(CIPluginInfo);
    String jsonB = dtoFactory.dtoToJson(newRef);
    assertEquals(jsonA, jsonB);
    CIPluginInfo CIPluginInfoImplDes = dtoFactory.dtoFromJson(jsonA, CIPluginInfo.class);
    assertNotNull(CIPluginInfoImplDes);
    assertEquals("1.2.3", CIPluginInfoImplDes.getVersion());
}
Also used : CIPluginInfo(com.hp.octane.integrations.dto.general.CIPluginInfo) Test(org.junit.Test)

Aggregations

CIPluginInfo (com.hp.octane.integrations.dto.general.CIPluginInfo)3 CIServerInfo (com.hp.octane.integrations.dto.general.CIServerInfo)2 Test (org.junit.Test)2 CIProviderSummaryInfo (com.hp.octane.integrations.dto.general.CIProviderSummaryInfo)1