Search in sources :

Example 1 with SourceMonitor

use of ddf.catalog.source.SourceMonitor in project ddf by codice.

the class ConfluenceSource method isAvailable.

@Override
public boolean isAvailable() {
    boolean isAvailable = false;
    if (!lastAvailable || (lastAvailableDate.before(new Date(System.currentTimeMillis() - availabilityPollInterval)))) {
        Response response = null;
        try {
            response = getClientFactory().getWebClient().head();
        } catch (Exception e) {
            LOGGER.debug("Web Client was unable to connect to endpoint.", e);
        }
        if (response != null && !(response.getStatus() >= HttpStatus.SC_NOT_FOUND || response.getStatus() == HttpStatus.SC_BAD_REQUEST || response.getStatus() == HttpStatus.SC_PAYMENT_REQUIRED)) {
            isAvailable = true;
            lastAvailableDate = new Date();
        }
    } else {
        isAvailable = lastAvailable;
    }
    if (lastAvailable != isAvailable) {
        for (SourceMonitor monitor : this.sourceMonitors) {
            if (isAvailable) {
                monitor.setAvailable();
            } else {
                monitor.setUnavailable();
            }
        }
    }
    lastAvailable = isAvailable;
    return isAvailable;
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) Response(javax.ws.rs.core.Response) SourceMonitor(ddf.catalog.source.SourceMonitor) Date(java.util.Date) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException)

Example 2 with SourceMonitor

use of ddf.catalog.source.SourceMonitor in project ddf by codice.

the class ConfluenceSourceTest method testAvaliabilitySourceMonitor.

@Test
public void testAvaliabilitySourceMonitor() throws Exception {
    SourceMonitor monitor = mock(SourceMonitor.class);
    WebClient mockClient = mock(WebClient.class);
    when(factory.getWebClient()).thenReturn(mockClient);
    Response mockResponse = mock(Response.class);
    when(mockClient.head()).thenReturn(mockResponse);
    when(mockResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    assertThat(confluence.isAvailable(monitor), is(true));
    verify(monitor).setAvailable();
    Thread.sleep(10);
    assertThat(confluence.isAvailable(monitor), is(false));
    verify(monitor).setUnavailable();
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Response(javax.ws.rs.core.Response) SourceMonitor(ddf.catalog.source.SourceMonitor) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 3 with SourceMonitor

use of ddf.catalog.source.SourceMonitor in project ddf by codice.

the class RegistryStoreImpl method init.

public void init() {
    SourceMonitor registrySourceMonitor = new SourceMonitor() {

        @Override
        public void setAvailable() {
            try {
                registryInfoQuery();
            } catch (UnsupportedQueryException e) {
                LOGGER.debug("Unable to query registry configurations, ", e);
            }
        }

        @Override
        public void setUnavailable() {
        }
    };
    addSourceMonitor(registrySourceMonitor);
    super.init();
}
Also used : UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) SourceMonitor(ddf.catalog.source.SourceMonitor)

Example 4 with SourceMonitor

use of ddf.catalog.source.SourceMonitor in project ddf by codice.

the class AbstractCswSource method availabilityChanged.

private void availabilityChanged(boolean isAvailable) {
    if (isAvailable) {
        LOGGER.debug("CSW source {} is available.", cswSourceConfiguration.getId());
    } else {
        LOGGER.debug("CSW source {} is unavailable.", cswSourceConfiguration.getId());
    }
    for (SourceMonitor monitor : this.sourceMonitors) {
        if (isAvailable) {
            LOGGER.debug("Notifying source monitor that CSW source {} is available.", cswSourceConfiguration.getId());
            monitor.setAvailable();
        } else {
            LOGGER.debug("Notifying source monitor that CSW source {} is unavailable.", cswSourceConfiguration.getId());
            monitor.setUnavailable();
        }
    }
}
Also used : SourceMonitor(ddf.catalog.source.SourceMonitor)

Example 5 with SourceMonitor

use of ddf.catalog.source.SourceMonitor in project ddf by codice.

the class WfsSource method availabilityChanged.

private void availabilityChanged(boolean isAvailable) {
    if (isAvailable) {
        LOGGER.info("WFS source {} is available.", getId());
    } else {
        LOGGER.info("WFS source {} is unavailable.", getId());
    }
    for (SourceMonitor monitor : this.sourceMonitors) {
        if (isAvailable) {
            LOGGER.debug("Notifying source monitor that WFS source {} is available.", getId());
            monitor.setAvailable();
        } else {
            LOGGER.debug("Notifying source monitor that WFS source {} is unavailable.", getId());
            monitor.setUnavailable();
        }
    }
}
Also used : SourceMonitor(ddf.catalog.source.SourceMonitor)

Aggregations

SourceMonitor (ddf.catalog.source.SourceMonitor)7 SourceResponse (ddf.catalog.operation.SourceResponse)2 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)2 Response (javax.ws.rs.core.Response)2 ResourceResponse (ddf.catalog.operation.ResourceResponse)1 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)1 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 IOException (java.io.IOException)1 Date (java.util.Date)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 RegistryStore (org.codice.ddf.registry.api.internal.RegistryStore)1 Test (org.junit.Test)1 BundleContext (org.osgi.framework.BundleContext)1