Search in sources :

Example 46 with RepositoryException

use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.

the class JdbcUserRepository method listAllServiceAccounts.

@Override
@JdbcTransaction
public List<ServiceAccountEntity> listAllServiceAccounts(byte[] filterPublicKey) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        List<ServiceAccountEntity> serviceAccounts = db.queries.listAllServiceAccounts();
        List<ServiceAccountEntity> ret = Lists.newArrayList();
        for (ServiceAccountEntity serviceAccount : serviceAccounts) {
            if (filterPublicKey != null) {
                if (!Objects.equal(filterPublicKey, serviceAccount.publicKeyData)) {
                    continue;
                }
            }
            ret.add(serviceAccount);
        }
        return ret;
    } catch (SQLException e) {
        throw new RepositoryException("Error listing service accounts", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 47 with RepositoryException

use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.

the class SimpleOperationQueue method jobFinished.

// @Override
// public JobExecutionList listRecentExecutions(ProjectId projectId) {
// JobExecutionList ret = JobExecutionList.create();
// synchronized (activeJobs) {
// for (ActiveJobExecution job : activeJobs.values()) {
// if (!Objects.equal(job.getTargetItemKey().getProject(), projectId)) {
// continue;
// }
// ret.add(job.getJobExecution());
// }
// }
//
// synchronized (recentJobs) {
// for (JobExecutionData jobExecution : recentJobs) {
// if (!jobExecution.getJobKey().getProject().equals(projectId)) {
// continue;
// }
// ret.add(jobExecution);
// }
// }
//
// return ret;
// }
// @Override
// public List<JobData> listRecentJobs(ProjectId projectId) {
// List<JobData> ret = Lists.newArrayList();
//
// synchronized (activeJobs) {
// for (ActiveJobExecution job : activeJobs.values()) {
// if (!Objects.equal(job.getTargetItemKey().getProject(), projectId)) {
// continue;
// }
// JobExecutionData execution = job.getJobExecution();
// ret.add(execution.getJob());
// }
// }
//
// synchronized (recentJobs) {
// for (JobExecutionData job : recentJobs) {
// if (!job.getJobKey().getProject().equals(projectId)) {
// continue;
// }
// ret.add(job.getJob());
// }
// }
//
// return ret;
// }
// private static final int RECENT_JOB_COUNT = 100;
@Override
public void jobFinished(JobExecutionData jobExecutionData, JobState state, JobLogger logger) throws OpsException {
    PlatformLayerKey jobKey = jobExecutionData.getJobKey();
    String executionId = jobExecutionData.getExecutionId();
    Date startTime = jobExecutionData.getStartedAt();
    Date endTime = new Date();
    synchronized (activeJobs) {
        activeJobs.remove(jobKey);
    }
    try {
        String logCookie = jobLogStore.saveJobLog(jobKey, executionId, startTime, logger);
        jobRepository.recordJobEnd(jobKey, executionId, endTime, state, logCookie);
    } catch (RepositoryException e) {
        throw new OpsException("Error writing job to repository", e);
    } catch (Exception e) {
        throw new OpsException("Error writing job log", e);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) RepositoryException(org.platformlayer.RepositoryException) Date(java.util.Date) RepositoryException(org.platformlayer.RepositoryException) OpsException(org.platformlayer.ops.OpsException)

Example 48 with RepositoryException

use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.

the class JdbcJobRepository method listExecutions.

// @Override
// @JdbcTransaction
// public void recordJob(PlatformLayerKey jobId, PlatformLayerKey itemKey, JobState jobState, JobLog jobLog)
// throws RepositoryException {
// DbHelper db = new DbHelper();
// try {
// String data;
//
// // TODO: More compact encoding?? XML InfoSet? GZIP?
// try {
// data = JaxbHelper.toXml(jobLog, false);
// } catch (JAXBException e) {
// throw new RepositoryException("Error serializing job log", e);
// }
//
// int updateCount = db.insertJobLog(itemKey.getServiceType(), itemKey.getItemType(), itemKey.getProject(),
// itemKey.getItemId(), jobState, data);
//
// if (updateCount != 1) {
// throw new IllegalStateException("Unexpected number of rows inserted");
// }
// } catch (SQLException e) {
// throw new RepositoryException("Error saving job log", e);
// } finally {
// db.close();
// }
// }
@Override
@JdbcTransaction
public List<JobExecutionData> listExecutions(PlatformLayerKey jobKey) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        ProjectId projectId = jobKey.getProject();
        String jobId = jobKey.getItemIdString();
        List<JobExecutionEntity> executions = db.queries.listExecutions(db.mapToValue(projectId), jobId);
        List<JobExecutionData> ret = Lists.newArrayList();
        for (JobExecutionEntity execution : executions) {
            ret.add(mapFromEntity(execution, jobKey));
        }
        sort(ret);
        return ret;
    } catch (SQLException e) {
        throw new RepositoryException("Error listing job executions", e);
    } finally {
        db.close();
    }
}
Also used : JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) SQLException(java.sql.SQLException) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 49 with RepositoryException

use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.

the class JdbcJobRepository method findExecution.

@Override
@JdbcTransaction
public JobExecutionData findExecution(PlatformLayerKey jobKey, String executionId) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        ProjectId projectId = jobKey.getProject();
        String jobId = jobKey.getItemIdString();
        JobExecutionEntity execution = db.queries.findExecution(db.mapToValue(projectId), jobId, executionId);
        if (execution == null) {
            return null;
        }
        return mapFromEntity(execution, jobKey);
    } catch (SQLException e) {
        throw new RepositoryException("Error listing job executions", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 50 with RepositoryException

use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.

the class JdbcJobRepository method insertExecution.

@Override
@JdbcTransaction
public String insertExecution(PlatformLayerKey jobKey, Date startedAt) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        ProjectId projectId = jobKey.getProject();
        String jobId = jobKey.getItemIdString();
        String executionId = UUID.randomUUID().toString();
        JobExecutionEntity execution = new JobExecutionEntity();
        execution.project = db.mapToValue(projectId);
        execution.startedAt = startedAt;
        execution.state = JobState.RUNNING;
        execution.executionId = executionId;
        execution.jobId = jobId;
        int updateCount = db.queries.insert(execution);
        if (updateCount != 1) {
            throw new RepositoryException("Unexpected number of rows inserted");
        }
        return execution.executionId;
    } catch (SQLException e) {
        throw new RepositoryException("Error inserting job execution", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Aggregations

RepositoryException (org.platformlayer.RepositoryException)56 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)30 SQLException (java.sql.SQLException)30 OpsException (org.platformlayer.ops.OpsException)18 ProjectId (org.platformlayer.ids.ProjectId)14 ItemBase (org.platformlayer.core.model.ItemBase)10 CryptoKey (com.fathomdb.crypto.CryptoKey)8 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)7 ManagedItemId (org.platformlayer.ids.ManagedItemId)7 OpsContext (org.platformlayer.ops.OpsContext)7 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)7 IOException (java.io.IOException)6 AesCryptoKey (com.fathomdb.crypto.AesCryptoKey)5 PublicKey (java.security.PublicKey)4 JAXBException (javax.xml.bind.JAXBException)4 Tag (org.platformlayer.core.model.Tag)4 ServiceType (org.platformlayer.ids.ServiceType)4 JobData (org.platformlayer.jobs.model.JobData)4 JoinedQueryResult (com.fathomdb.jpa.impl.JoinedQueryResult)3 X509Certificate (java.security.cert.X509Certificate)3