Search in sources :

Example 1 with IndexMetaData

use of com.netflix.exhibitor.core.index.IndexMetaData in project exhibitor by soabase.

the class IndexResource method getIndexedLogs.

@Path("indexed-logs")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIndexedLogs() {
    final DateFormat format = new SimpleDateFormat("MM/dd/yyyy-HH:mm");
    final IndexCache indexCache = context.getExhibitor().getIndexCache();
    IndexList indexList = new IndexList(new File(context.getExhibitor().getConfigManager().getConfig().getString(StringConfigs.LOG_INDEX_DIRECTORY)));
    GenericEntity<List<Index>> entity = new GenericEntity<List<Index>>(Lists.transform(indexList.getIndexes(), new Function<File, Index>() {

        @Override
        public Index apply(File f) {
            IndexMetaData metaData;
            try {
                metaData = indexCache.getMetaData(f);
            } catch (Exception e) {
                context.getExhibitor().getLog().add(ActivityLog.Type.ERROR, "Loading index metadata: " + f, e);
                metaData = new IndexMetaData(new Date(), new Date(), 0);
            }
            return new Index(f.getName(), format.format(metaData.getFrom()), format.format(metaData.getTo()), metaData.getEntryCount());
        }
    })) {
    };
    return Response.ok(entity).build();
}
Also used : Index(com.netflix.exhibitor.core.entities.Index) Date(java.util.Date) NameAndModifiedDate(com.netflix.exhibitor.core.entities.NameAndModifiedDate) IndexMetaData(com.netflix.exhibitor.core.index.IndexMetaData) Function(com.google.common.base.Function) GenericEntity(javax.ws.rs.core.GenericEntity) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) IndexCache(com.netflix.exhibitor.core.index.IndexCache) ArrayList(java.util.ArrayList) IndexList(com.netflix.exhibitor.core.index.IndexList) List(java.util.List) IndexList(com.netflix.exhibitor.core.index.IndexList) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Function (com.google.common.base.Function)1 Index (com.netflix.exhibitor.core.entities.Index)1 NameAndModifiedDate (com.netflix.exhibitor.core.entities.NameAndModifiedDate)1 IndexCache (com.netflix.exhibitor.core.index.IndexCache)1 IndexList (com.netflix.exhibitor.core.index.IndexList)1 IndexMetaData (com.netflix.exhibitor.core.index.IndexMetaData)1 File (java.io.File)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 GenericEntity (javax.ws.rs.core.GenericEntity)1