Search in sources :

Example 1 with ResourceCollectionDiff

use of net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff in project processdash by dtuma.

the class ResourceBridgeClient method getDiff.

private ResourceCollectionDiff getDiff() throws IOException {
    // start by initiating the HTTP connection to the server
    URLConnection conn = makeGetRequest(LIST_ACTION);
    conn.connect();
    // now, while the server is thinking, do our calculations locally.
    localCollection.validate();
    ResourceCollectionInfo localList = new ResourceListing(localCollection, ResourceFilterFactory.DEFAULT_FILTER);
    // finally, retrieve the list from the server and compare the two.
    serverVersion = conn.getHeaderField(VERSION_HEADER);
    ResourceCollectionInfo remoteList = XmlCollectionListing.parseListing(new BufferedInputStream(conn.getInputStream()));
    return new ResourceCollectionDiff(localList, remoteList);
}
Also used : ResourceCollectionInfo(net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo) ResourceListing(net.sourceforge.processdash.tool.bridge.ResourceListing) ResourceCollectionDiff(net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff) BufferedInputStream(java.io.BufferedInputStream) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection)

Example 2 with ResourceCollectionDiff

use of net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff in project processdash by dtuma.

the class CachingLocalImportDirectory method syncDown.

private void syncDown() throws IOException {
    // ensure the directories exist
    targetCollection.validate();
    cachedCollection.validate();
    // compute a difference between the two directories
    ResourceCollectionDiff diff = new ResourceCollectionDiff(targetCollection, cachedCollection);
    // delete any files that are only present in the cache
    for (String deletedFile : diff.getOnlyInB()) cachedCollection.deleteResource(deletedFile);
    // copy any files that are missing from the cache, or that differ
    syncFilesDown(diff.getOnlyInA(), diff.getDiffering());
}
Also used : ResourceCollectionDiff(net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff)

Example 3 with ResourceCollectionDiff

use of net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff in project processdash by dtuma.

the class ResourceBridgeClient method syncUp.

public synchronized boolean syncUp(SyncFilter filter) throws IOException, LockFailureException {
    if (userName == null)
        throw new NotLockedException();
    ProfTimer pt = new ProfTimer(logger, "ResourceBridgeClient.syncUp[" + remoteUrl + "]");
    ResourceCollectionDiff diff = getDiff();
    applySyncFilter(diff, filter);
    pt.click("Computed local-vs-remote diff");
    if (diff == null || diff.noDifferencesFound()) {
        logger.finer("no changes to sync up");
        return false;
    }
    boolean madeChange = false;
    List<String> filesToDownload = new ArrayList<String>();
    // collection (but not in our local collection)
    if (!diff.getOnlyInB().isEmpty()) {
        List<String> params = new ArrayList<String>();
        for (String resourceName : diff.getOnlyInB()) {
            if (isSyncDownOnly(resourceName)) {
                filesToDownload.add(resourceName);
            } else {
                logger.fine("deleting remote resource " + resourceName);
                params.add(DELETE_FILE_PARAM);
                params.add(resourceName);
            }
        }
        if (!params.isEmpty()) {
            doPostRequest(DELETE_ACTION, (Object[]) params.toArray());
            pt.click("Deleted remote resources");
            madeChange = true;
        }
    }
    // collection
    if (!diff.getOnlyInA().isEmpty() || !diff.getDiffering().isEmpty()) {
        List params = new ArrayList();
        for (String resourceName : diff.getOnlyInA()) {
            if (isSyncDownOnly(resourceName)) {
                logger.fine("deleting local resource " + resourceName);
                localCollection.deleteResource(resourceName);
                madeChange = true;
            } else {
                logger.fine("uploading new resource " + resourceName);
                addFileUploadParamsWithBatching(params, resourceName);
                madeChange = true;
            }
        }
        for (String resourceName : diff.getDiffering()) {
            if (isSyncDownOnly(resourceName)) {
                filesToDownload.add(resourceName);
            } else {
                logger.fine("uploading modified resource " + resourceName);
                addFileUploadParamsWithBatching(params, resourceName);
                madeChange = true;
            }
        }
        if (!params.isEmpty()) {
            startZipUploadThread(params);
            doPostRequest(UPLOAD_ACTION, (Object[]) params.toArray());
            pt.click("Uploaded new/modified resources");
            madeChange = true;
        }
    }
    if (!filesToDownload.isEmpty()) {
        List params = addMultiple(null, INCLUDE_PARAM, filesToDownload);
        downloadFiles(makeGetRequest(DOWNLOAD_ACTION, params));
        madeChange = true;
    }
    if (!madeChange) {
        logger.finer("no changes to sync up");
    }
    return madeChange;
}
Also used : ResourceCollectionDiff(net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff) ProfTimer(net.sourceforge.processdash.util.ProfTimer) ArrayList(java.util.ArrayList) NotLockedException(net.sourceforge.processdash.util.lock.NotLockedException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ResourceCollectionDiff

use of net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff in project processdash by dtuma.

the class ResourceBridgeClient method syncDown.

public synchronized boolean syncDown(SyncFilter filter) throws IOException {
    ProfTimer pt = new ProfTimer(logger, "ResourceBridgeClient.syncDown[" + remoteUrl + "]");
    // identical contents
    if (hashesMatch()) {
        pt.click("checked hashes - match");
        return false;
    }
    pt.click("checked hashes - mismatch");
    // as an optimization, download any files from the server that were
    // created/modified after our most recently changed file.
    long mostRecentLocalModTime = getMostRecentLocalModTime();
    downloadFiles(makeGetRequest(DOWNLOAD_ACTION, ResourceFilterFactory.LAST_MOD_PARAM, mostRecentLocalModTime));
    // now make a complete comparison of local-vs-remote changes.
    ResourceCollectionDiff diff = getDiff();
    applySyncFilter(diff, filter);
    pt.click("Computed local-vs-remote diff");
    if (diff == null || diff.noDifferencesFound())
        return false;
    // the remote collection), delete the local files.
    for (String resourceName : diff.getOnlyInA()) {
        logger.fine("deleting local resource " + resourceName);
        localCollection.deleteResource(resourceName);
    }
    // copy down files that are only present in the remote collection, as
    // well as any files that have changed
    List filesToDownload = new ArrayList();
    filesToDownload.addAll(diff.getOnlyInB());
    filesToDownload.addAll(diff.getDiffering());
    downloadFilesNamed(filesToDownload);
    pt.click("Copied down changes");
    return true;
}
Also used : ResourceCollectionDiff(net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff) ProfTimer(net.sourceforge.processdash.util.ProfTimer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ResourceCollectionDiff (net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ProfTimer (net.sourceforge.processdash.util.ProfTimer)2 BufferedInputStream (java.io.BufferedInputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URLConnection (java.net.URLConnection)1 ResourceCollectionInfo (net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo)1 ResourceListing (net.sourceforge.processdash.tool.bridge.ResourceListing)1 NotLockedException (net.sourceforge.processdash.util.lock.NotLockedException)1