use of org.platformlayer.ids.ManagedItemId in project platformlayer by platformlayer.
the class FederatedPlatformLayerClient method mapToChildForPut.
private MappedPlatformLayerKey mapToChildForPut(PlatformLayerKey plk) {
FederationMapping childKey = federationMap.getClientForCreate(plk);
ManagedItemId childItemId = plk.getItemId();
ChildClient childClient = getClient(childKey);
MappedPlatformLayerKey mapped = new MappedPlatformLayerKey();
mapped.child = childClient;
mapped.key = new PlatformLayerKey(childKey.host, childKey.project, plk.getServiceType(), plk.getItemType(), childItemId);
return mapped;
}
use of org.platformlayer.ids.ManagedItemId in project platformlayer by platformlayer.
the class PlatformLayerKey method parse.
public static PlatformLayerKey parse(String s) {
if (!s.contains("://")) {
int slashCount = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '/') {
slashCount++;
}
}
String extraSlashes = "";
if (slashCount < 4) {
extraSlashes = Strings.repeat("/", 4 - slashCount);
}
s = SCHEME + "://" + extraSlashes + s;
}
URI uri;
try {
uri = new URI(s);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Error parsing URI", e);
}
if (!Objects.equal(SCHEME, uri.getScheme())) {
throw new IllegalArgumentException();
}
FederationKey hostKey = null;
String host = uri.getHost();
if (!Strings.isNullOrEmpty(host)) {
hostKey = FederationKey.build(host);
}
String path = uri.getPath();
if (path.startsWith("/")) {
path = path.substring(1);
}
ArrayList<String> components = Lists.newArrayList(Splitter.on('/').split(path));
if (components.size() < 4) {
throw new IllegalArgumentException();
}
String componentProject = components.get(0);
ProjectId project = !Strings.isNullOrEmpty(componentProject) ? new ProjectId(componentProject) : null;
String serviceComponent = components.get(1);
ServiceType serviceType = !Strings.isNullOrEmpty(serviceComponent) ? new ServiceType(serviceComponent) : null;
ItemType itemType = new ItemType(components.get(2));
ManagedItemId itemId = new ManagedItemId(Joiner.on("/").join(components.subList(3, components.size())));
return new PlatformLayerKey(hostKey, project, serviceType, itemType, itemId);
}
use of org.platformlayer.ids.ManagedItemId 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.ids.ManagedItemId 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.ids.ManagedItemId in project platformlayer by platformlayer.
the class PlatformLayerTestContext method getItem.
public <T extends ItemBase> T getItem(String id, Class<T> itemClass) throws OpsException, IOException {
TypedPlatformLayerClient client = getTypedClient();
JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(itemClass, new Class[] {});
PlatformLayerKey key = PlatformLayerClientBase.toKey(jaxbHelper, new ManagedItemId(id), itemClass, client.listServices(true));
return client.getItem(key, itemClass);
}
Aggregations