use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.
the class JdbcJobRepository method actionFromXml.
private Action actionFromXml(String actionXml) throws RepositoryException {
Object o;
try {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
o = unmarshaller.unmarshal(new StringReader(actionXml));
} catch (JAXBException e) {
throw new RepositoryException("Error deserializing action", e);
}
return Casts.checkedCast(o, Action.class);
}
use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.
the class JdbcJobRepository method listRecentJobs.
// @Override
// @JdbcTransaction
// public List<JobExecutionData> listRecentExecutions(JobQuery jobQuery) throws RepositoryException {
// DbHelper db = new DbHelper();
// try {
// // We use JoinedQueryResult because we have a compound PK (projectId / jobId)
// // and JPA makes this really complicated.
//
// ProjectId projectId = jobQuery.project;
// Preconditions.checkNotNull(projectId);
// int project = db.mapToValue(projectId);
//
// Long maxAge = null;
// if (jobQuery.maxAge != null) {
// maxAge = jobQuery.maxAge.getTotalSeconds();
// }
//
// Integer limit = jobQuery.limit;
// String filterTarget = jobQuery.target != null ? jobQuery.target.getUrl() : null;
//
// JoinedQueryResult results = db.queries.listRecentExecutions(project, maxAge, filterTarget, limit);
//
// List<JobExecutionData> ret = Lists.newArrayList();
// Map<String, JobData> jobs = Maps.newHashMap();
//
// for (JobEntity job : results.getAll(JobEntity.class)) {
// ManagedItemId jobId = new ManagedItemId(job.jobId);
// PlatformLayerKey jobKey = JobData.buildKey(projectId, jobId);
// jobs.put(job.jobId, mapFromEntity(job, jobKey));
// }
//
// for (JobExecutionEntity execution : results.getAll(JobExecutionEntity.class)) {
// JobData jobData = jobs.get(execution.jobId);
// if (jobData == null) {
// throw new IllegalStateException();
// }
//
// ManagedItemId jobId = new ManagedItemId(execution.jobId);
// PlatformLayerKey jobKey = JobData.buildKey(projectId, jobId);
// JobExecutionData run = mapFromEntity(execution, jobKey);
// run.job = jobData;
// ret.add(run);
// }
//
// sort(ret);
//
// return ret;
// } catch (SQLException e) {
// throw new RepositoryException("Error listing job executions", e);
// } finally {
// db.close();
// }
// }
@Override
@JdbcTransaction
public List<JobData> listRecentJobs(JobQuery jobQuery) throws RepositoryException {
DbHelper db = new DbHelper();
try {
ProjectId projectId = jobQuery.project;
Preconditions.checkNotNull(projectId);
int project = db.mapToValue(projectId);
Long maxAge = null;
if (jobQuery.maxAge != null) {
maxAge = jobQuery.maxAge.getTotalSeconds();
}
Integer limit = jobQuery.limit;
String filterTarget = jobQuery.target != null ? jobQuery.target.getUrl() : null;
// TODO: Include currently running jobs...
List<JobEntity> results = db.queries.listRecentJobs(project, maxAge, filterTarget, limit);
List<JobData> ret = Lists.newArrayList();
for (JobEntity job : results) {
ManagedItemId jobId = new ManagedItemId(job.jobId);
PlatformLayerKey jobKey = JobData.buildKey(projectId, jobId);
JobData jobData = mapFromEntity(job, jobKey);
ret.add(jobData);
}
sortJobs(ret);
return ret;
} catch (SQLException e) {
throw new RepositoryException("Error listing job executions", e);
} finally {
db.close();
}
}
use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.
the class PersistentJobRegistry method enqueueOperation.
@Override
public JobData enqueueOperation(Action action, ProjectAuthorization auth, PlatformLayerKey targetItem) throws OpsException {
ProjectId projectId;
try {
projectId = opsContextBuilder.getRunAsProjectId(auth);
} catch (OpsException e) {
throw new OpsException("Error getting projectId", e);
}
JobData jobData = new JobData();
jobData.action = action;
jobData.targetId = targetItem;
try {
String jobId = repository.insertJob(projectId, jobData);
jobData.key = JobData.buildKey(projectId, new ManagedItemId(jobId));
} catch (RepositoryException e) {
throw new OpsException("Error inserting job", e);
}
operationQueue.submit(auth, jobData);
return jobData;
}
use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.
the class MetricsResource method getMetrics.
@POST
@Produces({ XML, JSON })
public MetricDataSource getMetrics(final MetricQuery query) throws RepositoryException, OpsException {
final ItemBase managedItem = getManagedItem();
final ServiceProvider serviceProvider = getServiceProvider();
OpsContextBuilder opsContextBuilder = objectInjector.getInstance(OpsContextBuilder.class);
final OpsContext opsContext = opsContextBuilder.buildTemporaryOpsContext(getServiceType(), getProjectAuthorization());
return OpsContext.runInContext(opsContext, new CheckedCallable<MetricDataSource, Exception>() {
@Override
public MetricDataSource call() throws Exception {
BindingScope bindingScope = BindingScope.push(managedItem, managedItem);
try {
MetricDataSource metrics = serviceProvider.getMetricValues(managedItem, query);
return metrics;
} finally {
bindingScope.pop();
}
}
});
}
use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.
the class KeystoneRepositoryAuthenticator method getUserFromToken.
@Override
public UserEntity getUserFromToken(String userIdString, byte[] tokenSecret) throws AuthenticatorException {
int userId;
try {
userId = Integer.parseInt(userIdString);
} catch (NumberFormatException e) {
throw new AuthenticatorException("Invalid user id", e);
}
if (tokenSecret.length < 1) {
throw new IllegalArgumentException();
}
CryptoKey userSecret = authenticationSecrets.decryptSecretFromToken(tokenSecret);
if (userSecret == null) {
throw new AuthenticatorException("Authentication timed out");
}
UserEntity user;
try {
user = repository.findUserById(userId);
} catch (RepositoryException e) {
throw new AuthenticatorException("Error while authenticating user", e);
}
user.unlock(userSecret);
if (user.isLocked()) {
return null;
}
return user;
}
Aggregations