Search in sources :

Example 6 with LockFailureException

use of net.sourceforge.processdash.util.lock.LockFailureException in project processdash by dtuma.

the class ResourceBridgeClient method checkForLockException.

/**
     * Look at the headers from an HTTP response, and see if they specify a lock
     * failure exception. If so, create an appropriate exception and throw it.
     * 
     * If the response headers do <b>not</b> specify a lock failure, this
     * method will do nothing and return.
     * 
     * @param conn
     *                a connection to a URL
     * @throws LockFailureException
     *                 if the connection was an HTTP connection and if the
     *                 response headers indicate a lock failure
     * @throws IOException
     *                 if an error occurred when attempting to examine the
     *                 response headers
     */
private static void checkForLockException(URLConnection conn) throws IOException, LockFailureException {
    if (conn instanceof HttpURLConnection) {
        HttpURLConnection http = (HttpURLConnection) conn;
        int code = http.getResponseCode();
        if (code != HttpURLConnection.HTTP_CONFLICT)
            return;
        String exceptionClass = http.getHeaderField(LOCK_EXCEPTION_HEADER);
        if (!StringUtils.hasValue(exceptionClass))
            return;
        if (exceptionClass.equals(AlreadyLockedException.class.getName())) {
            String extraInfo = http.getHeaderField(ALREADY_LOCKED_HEADER);
            throw new AlreadyLockedException(extraInfo);
        }
        LockFailureException lfe;
        try {
            Class clazz = Class.forName(exceptionClass);
            lfe = (LockFailureException) clazz.newInstance();
        } catch (Throwable t) {
            lfe = new LockFailureException(exceptionClass + ", " + http.getResponseMessage());
        }
        throw lfe;
    }
}
Also used : AlreadyLockedException(net.sourceforge.processdash.util.lock.AlreadyLockedException) HttpURLConnection(java.net.HttpURLConnection) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException)

Example 7 with LockFailureException

use of net.sourceforge.processdash.util.lock.LockFailureException in project processdash by dtuma.

the class MoveProjectWorker method lockOldDataDirectory.

/*
     * Methods to lock and unlock the old data directory
     */
private void lockOldDataDirectory() throws MoveProjectException {
    File lockFile = new File(oldTeamDataDir, LOCK_FILE);
    fileLock = new FileConcurrencyLock(lockFile);
    try {
        fileLock.acquireLock(null);
    } catch (AlreadyLockedException ale) {
        throw new MoveProjectException("teamDirInUse").append("lockOwner", ale.getExtraInfo());
    } catch (LockFailureException e) {
        throw new MoveProjectException("teamDirInUse");
    }
}
Also used : AlreadyLockedException(net.sourceforge.processdash.util.lock.AlreadyLockedException) FileConcurrencyLock(net.sourceforge.processdash.util.lock.FileConcurrencyLock) File(java.io.File) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException)

Example 8 with LockFailureException

use of net.sourceforge.processdash.util.lock.LockFailureException in project processdash by dtuma.

the class ProcessDashboard method configureWorkingDirectory.

private void configureWorkingDirectory(String location) {
    workingDirectory = WorkingDirectoryFactory.getInstance().get(location, WorkingDirectoryFactory.PURPOSE_DASHBOARD);
    if (JnlpRelauncher.maybeRelaunch(workingDirectory))
        System.exit(0);
    String locationDescr = workingDirectory.getDescription();
    try {
        lockMessageHandler = new LockMsgHandler();
        workingDirectory.acquireProcessLock(ACTIVATE_MESSAGE, lockMessageHandler);
    } catch (SentLockMessageException e) {
        System.exit(0);
    } catch (LockFailureException e) {
        displaySharingError(locationDescr);
        System.exit(1);
    }
    try {
        workingDirectory.prepare();
    } catch (HttpException.Unauthorized e) {
        displayStartupPermissionError("Unauthorized");
        System.exit(1);
    } catch (HttpException.Forbidden e) {
        displayStartupPermissionError("Forbidden");
        System.exit(1);
    } catch (IOException e) {
        String resKey;
        if (workingDirectory instanceof BridgedWorkingDirectory) {
            resKey = "Errors.Read_File_Error.Data_Server";
        } else {
            resKey = "Errors.Read_File_Error.Data_Directory";
        }
        displayStartupIOError(resKey, locationDescr, e);
        System.exit(1);
    }
    // Check to see if a legacy shortcut is being used to launch a dataset
    // that is now hosted on a team server.  If so, possibly configure the
    // team server URL as the "default team server."
    TeamServerSelector.maybeSetDefaultTeamServerUrl(workingDirectory);
    File cwd = workingDirectory.getDirectory();
    System.setProperty("user.dir", cwd.getAbsolutePath());
}
Also used : SentLockMessageException(net.sourceforge.processdash.util.lock.SentLockMessageException) BridgedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory) HttpException(net.sourceforge.processdash.util.HttpException) IOException(java.io.IOException) File(java.io.File) TeamSettingsFile(net.sourceforge.processdash.team.setup.TeamSettingsFile) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)

Example 9 with LockFailureException

use of net.sourceforge.processdash.util.lock.LockFailureException in project processdash by dtuma.

the class ProcessDashboard method tryToLockDataForWriting.

private void tryToLockDataForWriting() {
    String lockOwnerName = getOwnerName();
    String otherUser = null;
    try {
        workingDirectory.acquireWriteLock(lockMessageHandler, lockOwnerName);
        return;
    } catch (ReadOnlyLockFailureException ro) {
        showFilesAreReadOnlyMessage(workingDirectory.getDescription(), ro);
        return;
    } catch (CannotCreateLockException e) {
        showCannotCreateLockMessage(workingDirectory.getDescription(), e);
        return;
    } catch (OfflineLockLostException e) {
        showLostOfflineLockMessage(workingDirectory.getDescription(), e);
        return;
    } catch (AlreadyLockedException e) {
        otherUser = e.getExtraInfo();
    } catch (LockFailureException e) {
        showCannotCreateLockMessage(workingDirectory.getDescription(), e);
        return;
    }
    ResourceBundle r = ResourceBundle.getBundle("Templates.resources.ProcessDashboard");
    if (!StringUtils.hasValue(otherUser))
        otherUser = r.getString("Errors.Concurrent_Use_Someone_Else");
    String title = r.getString("Errors.Concurrent_Use_Title");
    String message = MessageFormat.format(r.getString("Errors.Concurrent_Use_Message2_FMT"), otherUser);
    if (JOptionPane.showConfirmDialog(hideSS(), message.split("\n"), title, JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
        InternalSettings.setReadOnly(true);
    } else {
        System.exit(0);
    }
}
Also used : OfflineLockLostException(net.sourceforge.processdash.util.lock.OfflineLockLostException) AlreadyLockedException(net.sourceforge.processdash.util.lock.AlreadyLockedException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException) CannotCreateLockException(net.sourceforge.processdash.util.lock.CannotCreateLockException) ResourceBundle(java.util.ResourceBundle) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)

Example 10 with LockFailureException

use of net.sourceforge.processdash.util.lock.LockFailureException in project processdash by dtuma.

the class PermissionsManager method saveUsers.

/**
     * Save in-memory user information to disk.
     */
private void saveUsers() {
    try {
        if (Settings.isReadOnly() || Settings.isPersonalMode())
            return;
        // open a file to save the users
        File tmp = TempFileFactory.get().createTempFile("users", ".dat");
        OutputStream out = new BufferedOutputStream(new RobustFileOutputStream(tmp));
        // start an XML document
        XmlSerializer xml = XMLUtils.getXmlSerializer(true);
        xml.setOutput(out, "UTF-8");
        xml.startDocument("UTF-8", null);
        xml.startTag(null, USERS_TAG);
        if (usersTimestamp != null)
            xml.attribute(null, TIMESTAMP_ATTR, XMLUtils.saveDate(usersTimestamp));
        // write XML for each user
        for (User u : getAllUsers()) {
            writeUser(xml, u);
        }
        // end the document and close the file
        xml.endTag(null, USERS_TAG);
        xml.ignorableWhitespace(System.lineSeparator());
        xml.endDocument();
        out.close();
        // add a tamper-deterrent thumbprint to the file
        TamperDeterrent.getInstance().addThumbprint(tmp, usersFile, TamperDeterrent.FileType.XML);
        tmp.delete();
        // from now forward, require a version of the dashboard that
        // understands and enforces users, roles and permissions
        DataVersionChecker.registerDataRequirement("pspdash", "2.3.2");
        // flush data so the PDES can update server-side permissions
        if (bridgedUrl != null)
            workingDir.flushData();
        this.usersDirty = false;
    } catch (IOException ioe) {
        logger.log(Level.WARNING, "Could not save users to " + usersFile, ioe);
    } catch (LockFailureException lfe) {
        logger.log(Level.WARNING, "Could not flush user data to server", lfe);
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Aggregations

LockFailureException (net.sourceforge.processdash.util.lock.LockFailureException)14 AlreadyLockedException (net.sourceforge.processdash.util.lock.AlreadyLockedException)10 IOException (java.io.IOException)8 HttpException (net.sourceforge.processdash.util.HttpException)7 ReadOnlyLockFailureException (net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)6 File (java.io.File)5 ProfTimer (net.sourceforge.processdash.util.ProfTimer)5 LockUncertainException (net.sourceforge.processdash.util.lock.LockUncertainException)5 NotLockedException (net.sourceforge.processdash.util.lock.NotLockedException)4 BridgedWorkingDirectory (net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory)3 SentLockMessageException (net.sourceforge.processdash.util.lock.SentLockMessageException)3 Random (java.util.Random)2 CompressedWorkingDirectory (net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory)2 WorkingDirectory (net.sourceforge.processdash.tool.bridge.client.WorkingDirectory)2 CannotCreateLockException (net.sourceforge.processdash.util.lock.CannotCreateLockException)2 HeadlessException (java.awt.HeadlessException)1 BufferedOutputStream (java.io.BufferedOutputStream)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1