Package org.apache.sling.hc.api.execution

Examples of org.apache.sling.hc.api.execution.HealthCheckExecutionResult


    @Override
    public AttributeList getAttributes(final String[] attributes) {
        final AttributeList result = new AttributeList();
        if ( attributes != null ) {
            HealthCheckExecutionResult hcResult = null;
            for(final String key : attributes) {
                final Object defaultValue = this.defaultAttributes.get(key);
                if ( defaultValue != null ) {
                    result.add(new Attribute(key, defaultValue));
                } else {
                    // we assume that a valid attribute name is used
                    // which is requesting a hc result
                    if ( hcResult == null ) {
                        hcResult = this.getHealthCheckResult();
                    }

                    if ( HC_OK_ATTRIBUTE_NAME.equals(key) ) {
                        result.add(new Attribute(key, hcResult.getHealthCheckResult().isOk()));
                    } else if ( HC_LOG_ATTRIBUTE_NAME.equals(key) ) {
                        try {
                            result.add(new Attribute(key, logData(hcResult.getHealthCheckResult())));
                        } catch ( final OpenDataException ignore ) {
                            // we ignore this and simply don't add the attribute
                        }
                    } else if ( HC_STATUS_ATTRIBUTE_NAME.equals(key) ) {
                        result.add(new Attribute(key, hcResult.getHealthCheckResult().getStatus().toString()));
                    } else if ( HC_ELAPSED_TIMED_ATTRIBUTE_NAME.equals(key) ) {
                        result.add(new Attribute(key, hcResult.getElapsedTimeInMs()));
                    } else if ( HC_FINISHED_AT_ATTRIBUTE_NAME.equals(key) ) {
                        result.add(new Attribute(key, hcResult.getFinishedAt()));
                    } else if ( HC_TIMED_OUT_ATTRIBUTE_NAME.equals(key) ) {
                        result.add(new Attribute(key, hcResult.hasTimedOut()));
                    }
                }
            }
        }
View Full Code Here


        healthCheckExecutorImpl.collectResultsFromFutures(futures, results);

        verify(future, times(0)).get();

        assertEquals(1, results.size());
        HealthCheckExecutionResult result = results.iterator().next();

        assertEquals(Result.Status.WARN, result.getHealthCheckResult().getStatus());

    }
View Full Code Here

        // use an old date now (simulating a future that has run for a min)
        when(future.getCreatedTime()).thenReturn(new Date(new Date().getTime() - 1000 * 60 * 60));

        healthCheckExecutorImpl.collectResultsFromFutures(futures, results);
        assertEquals(1, results.size());
        HealthCheckExecutionResult result = results.iterator().next();

        verify(future, times(0)).get();

        assertEquals(Result.Status.CRITICAL, result.getHealthCheckResult().getStatus());

    }
View Full Code Here

            final long resultCacheTtlInMs) {
        final Set<HealthCheckExecutionResult> cachedResults = new TreeSet<HealthCheckExecutionResult>();
        final Iterator<HealthCheckMetadata> checksIt = metadatas.iterator();
        while (checksIt.hasNext()) {
            final HealthCheckMetadata md = checksIt.next();
            final HealthCheckExecutionResult result = useValidCacheResults(md, resultCacheTtlInMs);
            if (result != null) {
                cachedResults.add(result);
                checksIt.remove();
            }
        }
View Full Code Here

        return get(metadata, resultCacheTtlInMs);
    }

    private HealthCheckExecutionResult get(final HealthCheckMetadata metadata, final long resultCacheTtlInMs) {
        final Long key = metadata.getServiceId();
        final HealthCheckExecutionResult cachedResult = cache.get(key);
        if (cachedResult != null) {
            Date finishedAt = cachedResult.getFinishedAt();
            if (finishedAt == null) {
                // never cache without proper meta data -> remove it
                cache.remove(key);
                return null;
            }
View Full Code Here

            }

            @Override
            public HealthCheckExecutionResult execute(ServiceReference ref) {
                // TODO Auto-generated method stub
                return new HealthCheckExecutionResult() {

                    @Override
                    public Result getHealthCheckResult() {
                        // TODO Auto-generated method stub
                        return testHealthCheck.execute();
View Full Code Here

    private HealthCheckExecutionResult createResultsForDescriptor(final HealthCheckMetadata metadata) {
        // -- All methods below check if they can transform a healthCheckDescriptor into a result
        // -- if yes the descriptor is removed from the list and the result added

        // reuse cached results where possible
        HealthCheckExecutionResult result;

        result = healthCheckResultCache.useValidCacheResults(metadata, resultCacheTtlInMs);

        if ( result == null ) {
            final HealthCheckFuture future;
View Full Code Here

        final Set<HealthCheckExecutionResult> resultsFromFutures = new HashSet<HealthCheckExecutionResult>();

        final Iterator<HealthCheckFuture> futuresIt = futuresForResultOfThisCall.iterator();
        while (futuresIt.hasNext()) {
            final HealthCheckFuture future = futuresIt.next();
            final HealthCheckExecutionResult result = this.collectResultFromFuture(future);

            resultsFromFutures.add(result);
            futuresIt.remove();
        }
View Full Code Here

     * @param future The future
     * @return The execution result or a result for a reached timeout
     */
    HealthCheckExecutionResult collectResultFromFuture(final HealthCheckFuture future) {

        HealthCheckExecutionResult result;
        if (future.isDone()) {
            logger.debug("Health Check is done: {}", future.getHealthCheckMetadata());

            try {
                result = future.get();
View Full Code Here

    @Test
    public void testAnnotatedHC() {
        final List<HealthCheckExecutionResult> results = executor.execute("annotation","sample");
        assertNotNull("Expecting non-null results");
        assertEquals("Expecting a single result", 1, results.size());
        final HealthCheckExecutionResult r = results.get(0);
        assertTrue("Expecting non-empty HC log", r.getHealthCheckResult().iterator().hasNext());
        final String expected = "All good";
        assertTrue(
                "Expecting first log message to contain " + expected,
                r.getHealthCheckResult().iterator().next().getMessage().contains(expected));
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.hc.api.execution.HealthCheckExecutionResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.