Search in sources :

Example 1 with CacheEntry

use of com.att.aro.core.packetanalysis.pojo.CacheEntry in project VideoOptimzer by attdevsupport.

the class DuplicateContentImpl method runTest.

@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
    DuplicateContentResult result = new DuplicateContentResult();
    CacheAnalysis cacheAnalysis = tracedata.getCacheAnalysis();
    result.setDuplicateContentBytes(cacheAnalysis.getDuplicateContentBytes());
    result.setDuplicateContentBytesRatio(cacheAnalysis.getDuplicateContentBytesRatio());
    int duplicateContentsize = cacheAnalysis.getDuplicateContent().size();
    result.setDuplicateContentsize(duplicateContentsize);
    long totalTCPBytes = 0;
    if (tracedata.getStatistic() != null) {
        totalTCPBytes = tracedata.getStatistic().getTotalTCPPayloadBytes();
    }
    result.setTotalContentBytes(totalTCPBytes);
    List<CacheEntry> caUResult = cacheAnalysis.getDuplicateContent();
    result.setDuplicateContentList(caUResult);
    int duplicateContentSizeOfUniqueItems = caUResult.size();
    result.setDuplicateContentSizeOfUniqueItems(duplicateContentSizeOfUniqueItems);
    if (duplicateContentsize <= 3) {
        result.setResultType(BPResultType.PASS);
        result.setResultText(textResultPass);
        result.setResultExcelText(BPResultType.PASS.getDescription());
    } else {
        result.setResultType(BPResultType.FAIL);
        DecimalFormat numf = new DecimalFormat("#.##");
        NumberFormat numf2 = NumberFormat.getInstance();
        numf2.setMaximumFractionDigits(3);
        String text = MessageFormat.format(textResults, numf.format(result.getDuplicateContentBytes() * 100.0 / result.getTotalContentBytes()), result.getDuplicateContentSizeOfUniqueItems(), numf2.format(((double) result.getDuplicateContentBytes()) / DUPLICATE_CONTENT_DENOMINATOR), numf2.format(((double) result.getTotalContentBytes()) / DUPLICATE_CONTENT_DENOMINATOR));
        result.setResultText(text);
        result.setResultExcelText(MessageFormat.format(textExcelResults, BPResultType.FAIL.getDescription(), result.getDuplicateContentSizeOfUniqueItems(), numf2.format(((double) result.getDuplicateContentBytes()) / DUPLICATE_CONTENT_DENOMINATOR), numf2.format(((double) result.getTotalContentBytes()) / DUPLICATE_CONTENT_DENOMINATOR), numf.format(result.getDuplicateContentBytes() * 100.0 / result.getTotalContentBytes())));
    }
    result.setAboutText(aboutText);
    result.setDetailTitle(detailTitle);
    result.setLearnMoreUrl(learnMoreUrl);
    result.setOverviewTitle(overviewTitle);
    result.setExportAllFiles(exportAllFiles);
    result.setExportAllPct(exportAllPct);
    result.setStaticsUnitsMbytes(staticsUnitsMbytes);
    return result;
}
Also used : DuplicateContentResult(com.att.aro.core.bestpractice.pojo.DuplicateContentResult) CacheAnalysis(com.att.aro.core.packetanalysis.pojo.CacheAnalysis) DecimalFormat(java.text.DecimalFormat) CacheEntry(com.att.aro.core.packetanalysis.pojo.CacheEntry) NumberFormat(java.text.NumberFormat)

Example 2 with CacheEntry

use of com.att.aro.core.packetanalysis.pojo.CacheEntry in project VideoOptimzer by attdevsupport.

the class CacheControlImpl method runTest.

@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
    CacheControlResult result = new CacheControlResult();
    if (tracedata.getCacheAnalysis() == null) {
        return null;
    }
    int hitNotExpiredDup = 0;
    int hitExpired304 = 0;
    for (CacheEntry entry : tracedata.getCacheAnalysis().getDiagnosisResults()) {
        if (entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP || entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT) {
            hitNotExpiredDup++;
        } else if (entry.getDiagnosis() == Diagnosis.CACHING_DIAG_OBJ_NOT_CHANGED_304) {
            hitExpired304++;
        }
    }
    boolean cacheControl = (hitNotExpiredDup > hitExpired304 ? false : true);
    if (cacheControl) {
        result.setResultType(BPResultType.PASS);
        result.setResultText(textResultPass);
        result.setResultExcelText(BPResultType.PASS.getDescription());
    } else {
        // ref. old analyzer give warning in this best practice
        result.setResultType(BPResultType.WARNING);
        String text = MessageFormat.format(textResults, hitNotExpiredDup, hitExpired304);
        result.setResultText(text);
        result.setResultExcelText(MessageFormat.format(textExcelResults, BPResultType.WARNING.getDescription(), hitNotExpiredDup, hitExpired304));
    }
    result.setHitExpired304Count(hitExpired304);
    result.setHitNotExpiredDupCount(hitNotExpiredDup);
    result.setAboutText(aboutText);
    result.setDetailTitle(detailTitle);
    result.setLearnMoreUrl(learnMoreUrl);
    result.setOverviewTitle(overviewTitle);
    result.setExportAllCacheCon304Desc(exportAllCacheCon304Desc);
    result.setExportAllCacheConNExpDesc(exportAllCacheConNExpDesc);
    return result;
}
Also used : CacheControlResult(com.att.aro.core.bestpractice.pojo.CacheControlResult) CacheEntry(com.att.aro.core.packetanalysis.pojo.CacheEntry)

Example 3 with CacheEntry

use of com.att.aro.core.packetanalysis.pojo.CacheEntry in project VideoOptimzer by attdevsupport.

the class CacheAnalysisImpl method analyze.

@Override
public CacheAnalysis analyze(List<Session> sessionlist) {
    long analysisStartTime = System.currentTimeMillis();
    CacheAnalysis result = new CacheAnalysis();
    long totalRequestResponseBytes = 0;
    long totalRequestResponseDupBytes = 0;
    double duplicateContentBytesRatio = 0.0;
    Map<String, CacheEntry> cacheEntries = new HashMap<String, CacheEntry>();
    Map<String, CacheEntry> dupEntries = new HashMap<String, CacheEntry>();
    Map<String, SortedSet<Range>> rangeEntries = new HashMap<String, SortedSet<Range>>();
    List<CacheEntry> diagnosisResults = new ArrayList<CacheEntry>();
    List<CacheEntry> duplicateContent = new ArrayList<CacheEntry>();
    List<CacheEntry> duplicateContentWithOriginals = new ArrayList<CacheEntry>();
    Map<CacheExpiration, List<CacheEntry>> cacheExpirationResponses = result.getCacheExpirationResponses();
    duplicateEntries = new ArrayList<DuplicateEntry>();
    // Initialize cache expiration lists
    for (CacheExpiration expiration : CacheExpiration.values()) {
        cacheExpirationResponses.put(expiration, new ArrayList<CacheEntry>());
    }
    // Build a sorted list of all of the HTTP request/response in the trace
    List<HttpRequestResponseInfoWithSession> rrInfo = new ArrayList<HttpRequestResponseInfoWithSession>();
    for (Session session : sessionlist) {
        if (!session.isUdpOnly()) {
            // rrInfo.addAll(session.getRequestResponseInfo());
            for (HttpRequestResponseInfo item : session.getRequestResponseInfo()) {
                HttpRequestResponseInfoWithSession itemsession = new HttpRequestResponseInfoWithSession();
                itemsession.setInfo(item);
                itemsession.setSession(session);
                rrInfo.add(itemsession);
            }
        }
    }
    Collections.sort(rrInfo);
    // Iterate through responses looking for duplicates
    for (HttpRequestResponseInfoWithSession httpreqres : rrInfo) {
        HttpRequestResponseInfo response = httpreqres.getInfo();
        Session session = httpreqres.getSession();
        PacketInfo firstPacket = session.getTcpPackets().get(0);
        if (response.getDirection() == HttpDirection.REQUEST) {
            // We only want to process responses
            continue;
        }
        // Check whether response is valid
        int statusCode = response.getStatusCode();
        if (statusCode == 0) {
            diagnosisResults.add(new CacheEntry(null, response, Diagnosis.CACHING_DIAG_INVALID_RESPONSE, 0, firstPacket));
            continue;
        }
        if (statusCode != 200 && statusCode != 206) {
            diagnosisResults.add(new CacheEntry(null, response, Diagnosis.CACHING_DIAG_INVALID_REQUEST, 0, firstPacket));
            continue;
        }
        // [A] Find corresponding request
        HttpRequestResponseInfo request = response.getAssocReqResp();
        if (request == null) {
            diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_REQUEST_NOT_FOUND, 0, firstPacket));
            continue;
        }
        totalRequestResponseBytes += response.getContentLength();
        // Request must by GET, POST, or PUT
        String requestType = request.getRequestType();
        if (!HttpRequestResponseInfo.HTTP_GET.equals(requestType) && !HttpRequestResponseInfo.HTTP_PUT.equals(requestType) && !HttpRequestResponseInfo.HTTP_POST.equals(requestType)) {
            diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_INVALID_REQUEST, 0, firstPacket));
            continue;
        }
        // Check for valid object name and host name
        if (request.getHostName() == null || request.getObjName() == null) {
            diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_INVALID_OBJ_NAME, 0, firstPacket));
            continue;
        }
        // [B] Object cacheable?
        if (response.isNoStore() || request.isNoStore() || HttpRequestResponseInfo.HTTP_POST.equals(requestType) || HttpRequestResponseInfo.HTTP_PUT.equals(requestType)) {
            cacheEntries.remove(getObjFullName(request, response));
            dupEntries.remove(getObjDuplicateName(request, response));
            diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_NOT_CACHABLE, 0, firstPacket));
            continue;
        }
        // [C] Does it hit the cache?
        CacheEntry cacheEntry = cacheEntries.get(getObjFullName(request, response));
        CacheEntry cacheDuplicateEntry = dupEntries.get(getObjDuplicateName(request, response));
        CacheEntry newCacheEntry;
        if (cacheEntry == null) {
            Diagnosis diagnosis = Diagnosis.CACHING_DIAG_CACHE_MISSED;
            newCacheEntry = new CacheEntry(request, response, diagnosis, firstPacket);
            newCacheEntry.setSession(session);
            addToCache(newCacheEntry, rangeEntries, cacheEntries, dupEntries, session);
            newCacheEntry.setCacheCount(1);
            diagnosisResults.add(newCacheEntry);
            if (cacheDuplicateEntry != null) {
                diagnosis = Diagnosis.CACHING_DIAG_ETAG_DUPLICATE;
            }
            duplicateEntries.add(new DuplicateEntry(request, response, diagnosis, firstPacket, session, getContent(response, session)));
            continue;
        } else {
            int oldCount = cacheEntry.getCacheCount();
            cacheEntry.setCacheCount(oldCount + 1);
        }
        CacheExpiration expStatus = cacheExpired(cacheEntry, request.getAbsTimeStamp());
        SortedSet<Range> ranges = rangeEntries.get(getObjFullName(cacheEntry.getRequest(), cacheEntry.getResponse()));
        boolean isfullcachehit = isFullCacheHit(response, ranges);
        if (isfullcachehit) {
            // [D] Is it expired?
            switch(expStatus) {
                case CACHE_EXPIRED:
                case CACHE_EXPIRED_HEURISTIC:
                    newCacheEntry = handleCacheExpired(session, response, request, firstPacket, cacheEntry);
                    diagnosisResults.add(newCacheEntry);
                    break;
                case CACHE_NOT_EXPIRED:
                case CACHE_NOT_EXPIRED_HEURISTIC:
                    newCacheEntry = new CacheEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP, firstPacket);
                    duplicateEntries.add(new DuplicateEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP, firstPacket, session, getContent(response, session)));
                    diagnosisResults.add(newCacheEntry);
                    break;
                default:
                    // Should not occur
                    newCacheEntry = null;
            }
        } else {
            long bytesInCache = getBytesInCache(response, ranges);
            // [D] Is it expired?
            switch(expStatus) {
                case CACHE_EXPIRED:
                case CACHE_EXPIRED_HEURISTIC:
                    newCacheEntry = handleCacheExpiredWithByteInCache(session, response, request, firstPacket, cacheEntry, bytesInCache);
                    diagnosisResults.add(newCacheEntry);
                    break;
                case CACHE_NOT_EXPIRED:
                case CACHE_NOT_EXPIRED_HEURISTIC:
                    newCacheEntry = new CacheEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT, bytesInCache, firstPacket);
                    duplicateEntries.add(new DuplicateEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP, firstPacket, session, getContent(response, session)));
                    diagnosisResults.add(newCacheEntry);
                    break;
                default:
                    // Should not occur
                    newCacheEntry = null;
            }
        }
        cacheExpirationResponses.get(expStatus).add(newCacheEntry);
        if (newCacheEntry != null) {
            newCacheEntry.setCacheHit(cacheEntry);
        }
    // addToCache(newCacheEntry);
    }
    // END: Iterate through responses looking for duplicates
    // Get cache problems
    Set<CacheEntry> dupsWithOrig = new HashSet<CacheEntry>();
    Map<String, DuplicateEntry> duplicateEntriesMap = new HashMap<String, DuplicateEntry>();
    CacheEntry cache;
    for (DuplicateEntry dupEntry : duplicateEntries) {
        if (dupEntry.getContentLength() > 0) {
            String key = dupEntry.getRequest().getHostName() + dupEntry.getHttpObjectName() + dupEntry.getContentLength();
            if (dupEntry.getHttpObjectName() != null) {
                if (!duplicateEntriesMap.containsKey(key)) {
                    dupEntry.setCount(1);
                    duplicateEntriesMap.put(key, dupEntry);
                } else {
                    if (Arrays.equals(duplicateEntriesMap.get(key).getContent(), dupEntry.getContent())) {
                        int count = duplicateEntriesMap.get(key).getCount();
                        if (count == 1) {
                            cache = new CacheEntry(duplicateEntriesMap.get(key).getRequest(), duplicateEntriesMap.get(key).getResponse(), duplicateEntriesMap.get(key).getDiagnosis(), duplicateEntriesMap.get(key).getSessionFirstPacket());
                            cache.setSession(dupEntry.getSession());
                            dupsWithOrig.add(cache);
                        }
                        cache = new CacheEntry(dupEntry.getRequest(), dupEntry.getResponse(), dupEntry.getDiagnosis(), dupEntry.getSessionFirstPacket());
                        dupsWithOrig.add(cache);
                        dupEntry = new DuplicateEntry(dupEntry.getRequest(), dupEntry.getResponse(), dupEntry.getDiagnosis(), dupEntry.getSessionFirstPacket(), dupEntry.getSession(), dupEntry.getContent());
                        dupEntry.setCount(count + 1);
                        duplicateEntriesMap.replace(key, dupEntry);
                    }
                }
            }
        }
    }
    for (Entry<String, DuplicateEntry> cacheEntry2 : duplicateEntriesMap.entrySet()) {
        if (cacheEntry2.getValue().getCount() > 1) {
            int count = cacheEntry2.getValue().getCount();
            cache = new CacheEntry(cacheEntry2.getValue().getRequest(), cacheEntry2.getValue().getResponse(), cacheEntry2.getValue().getDiagnosis(), cacheEntry2.getValue().getSessionFirstPacket());
            cache.setHitCount(count);
            if (count > 2) {
                totalRequestResponseDupBytes += (cacheEntry2.getValue().getHttpRequestResponse().getContentLength() * (count - 1));
            } else {
                totalRequestResponseDupBytes += cacheEntry2.getValue().getHttpRequestResponse().getContentLength();
            }
            duplicateContent.add(cache);
        }
    }
    duplicateContentWithOriginals.addAll(dupsWithOrig);
    Collections.sort(duplicateContentWithOriginals);
    duplicateContentBytesRatio = totalRequestResponseBytes != 0 ? (double) totalRequestResponseDupBytes / totalRequestResponseBytes : 0.0;
    result.setCacheExpirationResponses(cacheExpirationResponses);
    result.setDiagnosisResults(diagnosisResults);
    result.setDuplicateContent(duplicateContent);
    result.setDuplicateContentBytesRatio(duplicateContentBytesRatio);
    result.setDuplicateContentWithOriginals(duplicateContentWithOriginals);
    result.setTotalRequestResponseBytes(totalRequestResponseBytes);
    result.setTotalRequestResponseDupBytes(totalRequestResponseDupBytes);
    GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsTimings(cacheAnalysisTitle, System.currentTimeMillis() - analysisStartTime, analysisCategory);
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SortedSet(java.util.SortedSet) DuplicateEntry(com.att.aro.core.packetanalysis.pojo.DuplicateEntry) ArrayList(java.util.ArrayList) List(java.util.List) Diagnosis(com.att.aro.core.packetanalysis.pojo.Diagnosis) CacheExpiration(com.att.aro.core.packetanalysis.pojo.CacheExpiration) HashSet(java.util.HashSet) HttpRequestResponseInfoWithSession(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfoWithSession) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) CacheEntry(com.att.aro.core.packetanalysis.pojo.CacheEntry) Range(com.att.aro.core.packetanalysis.pojo.Range) CacheAnalysis(com.att.aro.core.packetanalysis.pojo.CacheAnalysis) ICacheAnalysis(com.att.aro.core.packetanalysis.ICacheAnalysis) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) HttpRequestResponseInfoWithSession(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfoWithSession) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 4 with CacheEntry

use of com.att.aro.core.packetanalysis.pojo.CacheEntry in project VideoOptimzer by attdevsupport.

the class UsingCacheImplTest method runTest_.

@Test
public void runTest_() {
    List<CacheEntry> diagnosisResults = new ArrayList<CacheEntry>();
    Mockito.when(entryArray[0].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_REQUEST_NOT_FOUND);
    Mockito.when(entryArray[1].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_INVALID_OBJ_NAME);
    Mockito.when(entryArray[2].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_INVALID_REQUEST);
    Mockito.when(entryArray[3].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_INVALID_RESPONSE);
    for (int i = 0; i < 4; i++) {
        diagnosisResults.add(entryArray[i]);
    }
    Mockito.when(cacheAnalysis.getDiagnosisResults()).thenReturn(diagnosisResults);
    Mockito.when(tracedata.getCacheAnalysis()).thenReturn(cacheAnalysis);
    AbstractBestPracticeResult testResult = usingCacheImpl.runTest(tracedata);
    assertEquals(BPResultType.PASS, testResult.getResultType());
}
Also used : ArrayList(java.util.ArrayList) AbstractBestPracticeResult(com.att.aro.core.bestpractice.pojo.AbstractBestPracticeResult) CacheEntry(com.att.aro.core.packetanalysis.pojo.CacheEntry) Test(org.junit.Test) BaseTest(com.att.aro.core.BaseTest)

Example 5 with CacheEntry

use of com.att.aro.core.packetanalysis.pojo.CacheEntry in project VideoOptimzer by attdevsupport.

the class ARODiagnosticsOverviewRouteImpl method updateOverviewTab.

public void updateOverviewTab(Object routeInfo) {
    int oldPanelIndex = jtabbedPane.getSelectedIndex();
    jtabbedPane.setSelectedIndex(OVERVIEW_INDEX);
    OverviewTab overviewTab = (OverviewTab) jtabbedPane.getSelectedComponent();
    if (routeInfo == null) {
        jtabbedPane.setSelectedIndex(oldPanelIndex);
        LOG.error("Overview Tab needs a type for updating");
        return;
    }
    LOG.debug("Type used to route to Overview Tab: " + routeInfo.getClass().getSimpleName());
    if (routeInfo instanceof CacheEntry) {
        overviewTab.setHighlightedDuplicate((CacheEntry) routeInfo);
    } else {
        jtabbedPane.setSelectedIndex(oldPanelIndex);
        LOG.error("Overview Tab cannot handle a type of " + routeInfo.getClass().getSimpleName() + " for updating");
    }
}
Also used : OverviewTab(com.att.aro.ui.view.overviewtab.OverviewTab) CacheEntry(com.att.aro.core.packetanalysis.pojo.CacheEntry)

Aggregations

CacheEntry (com.att.aro.core.packetanalysis.pojo.CacheEntry)23 ArrayList (java.util.ArrayList)7 BaseTest (com.att.aro.core.BaseTest)6 AbstractBestPracticeResult (com.att.aro.core.bestpractice.pojo.AbstractBestPracticeResult)6 Test (org.junit.Test)6 HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)4 DuplicateEntry (com.att.aro.core.packetanalysis.pojo.DuplicateEntry)3 Session (com.att.aro.core.packetanalysis.pojo.Session)3 CacheAnalysis (com.att.aro.core.packetanalysis.pojo.CacheAnalysis)2 Diagnosis (com.att.aro.core.packetanalysis.pojo.Diagnosis)2 PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)2 DataTablePopupMenu (com.att.aro.ui.model.DataTablePopupMenu)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 JButton (javax.swing.JButton)2 CacheControlResult (com.att.aro.core.bestpractice.pojo.CacheControlResult)1 DisplayNoneInCSSEntry (com.att.aro.core.bestpractice.pojo.DisplayNoneInCSSEntry)1 DuplicateContentResult (com.att.aro.core.bestpractice.pojo.DuplicateContentResult)1