Search in sources :

Example 1 with DataLayerException

use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.

the class TokenDataStore method create.

/**
     * Create an object. The id field will be populated with the resulting identifier.
     *
     * @param obj The object being created.
     * @throws ServerException When an error occurs during creation.
     */
public void create(T obj) throws ServerException {
    Token token = adapter.toToken(obj);
    SyncResultHandler<Token> handler = new SyncResultHandler<Token>();
    try {
        taskExecutor.execute(token.getTokenId(), taskFactory.create(token, handler));
        handler.getResults();
    } catch (ServerException e) {
        throw e;
    } catch (DataLayerException e) {
        if (debug.warningEnabled()) {
            debug.warning("Unable to create token corresponding", e);
        }
        throw new ServerException("Could not create token in token data store: " + e.getMessage());
    }
}
Also used : DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException) Token(org.forgerock.openam.cts.api.tokens.Token)

Example 2 with DataLayerException

use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.

the class TokenDataStore method update.

/**
     * Update a given instance.
     *
     * @param obj The object being updated.
     * @throws ServerException When the object cannot be found, or an error occurs during update.
     */
public void update(T obj) throws NotFoundException, ServerException {
    SyncResultHandler<Token> handler = new SyncResultHandler<Token>();
    Token token = adapter.toToken(obj);
    try {
        // Check it exists
        read(token.getTokenId());
        // Update it
        taskExecutor.execute(token.getTokenId(), taskFactory.update(token, handler));
        handler.getResults();
    } catch (ServerException e) {
        throw e;
    } catch (NotFoundException e) {
        throw e;
    } catch (DataLayerException e) {
        if (debug.warningEnabled()) {
            debug.warning("Unable to create token corresponding", e);
        }
        throw new ServerException("Could not create token in token data store: " + e.getMessage());
    }
}
Also used : DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException) Token(org.forgerock.openam.cts.api.tokens.Token)

Example 3 with DataLayerException

use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.

the class PooledTaskExecutor method execute.

@Override
public void execute(String tokenId, Task task) throws DataLayerException {
    try {
        debug("Polling pool for an executor");
        semaphore.acquire();
    } catch (InterruptedException e) {
        Thread.interrupted();
        throw new DataLayerException("Interrupted while waiting for executor - cannot continue", e);
    }
    SimpleTaskExecutor executor = pool.poll();
    if (executor == null) {
        executor = createExecutor();
    }
    try {
        debug("Got an executor - executing task");
        executor.execute(tokenId, task);
    } finally {
        debug("Returning executor to the pool");
        if (pool.add(executor)) {
            semaphore.release();
        }
    }
}
Also used : DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException)

Example 4 with DataLayerException

use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.

the class ReaperConnection method initConnection.

/**
     * If this is the first call, then initialise the connection.
     *
     * @throws org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException If there was an error getting the connection.
     */
private void initConnection() throws LdapInitializationFailedException {
    if (connection == null) {
        try {
            connection = factory.create();
            impl.setConnection(connection);
        } catch (DataLayerException e) {
            throw new LdapInitializationFailedException(e);
        }
    }
}
Also used : DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException) LdapInitializationFailedException(org.forgerock.openam.cts.exceptions.LdapInitializationFailedException)

Example 5 with DataLayerException

use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.

the class RemoveReferralsStep method deleteExistingReferrals.

private void deleteExistingReferrals() throws UpgradeException {
    try (Connection connection = getConnection()) {
        for (DN referral : referralsToBeRemoved) {
            UpgradeProgress.reportStart(AUDIT_REMOVING_REFERRAL_START, referral);
            DeleteRequest request = LDAPRequests.newDeleteRequest(referral);
            connection.delete(request);
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
        }
    } catch (DataLayerException | LdapException e) {
        UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
        throw new UpgradeException("Failed to delete referrals", e);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException) Connection(org.forgerock.opendj.ldap.Connection) DN(org.forgerock.opendj.ldap.DN) DeleteRequest(org.forgerock.opendj.ldap.requests.DeleteRequest) LdapException(org.forgerock.opendj.ldap.LdapException)

Aggregations

DataLayerException (org.forgerock.openam.sm.datalayer.api.DataLayerException)11 Token (org.forgerock.openam.cts.api.tokens.Token)4 Test (org.testng.annotations.Test)3 Task (org.forgerock.openam.sm.datalayer.api.Task)2 Collection (java.util.Collection)1 LdapInitializationFailedException (org.forgerock.openam.cts.exceptions.LdapInitializationFailedException)1 CreateTask (org.forgerock.openam.sm.datalayer.impl.tasks.CreateTask)1 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)1 Connection (org.forgerock.opendj.ldap.Connection)1 DN (org.forgerock.opendj.ldap.DN)1 LdapException (org.forgerock.opendj.ldap.LdapException)1 DeleteRequest (org.forgerock.opendj.ldap.requests.DeleteRequest)1