Search in sources :

Example 16 with ManagedItemId

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;
}
Also used : PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Example 17 with ManagedItemId

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);
}
Also used : ItemType(org.platformlayer.ids.ItemType) ProjectId(org.platformlayer.ids.ProjectId) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ManagedItemId(org.platformlayer.ids.ManagedItemId) FederationKey(org.platformlayer.ids.FederationKey) ServiceType(org.platformlayer.ids.ServiceType)

Example 18 with ManagedItemId

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();
    }
}
Also used : SQLException(java.sql.SQLException) ProjectId(org.platformlayer.ids.ProjectId) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) RepositoryException(org.platformlayer.RepositoryException) ManagedItemId(org.platformlayer.ids.ManagedItemId) JobData(org.platformlayer.jobs.model.JobData) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 19 with ManagedItemId

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;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException) JobData(org.platformlayer.jobs.model.JobData) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Example 20 with ManagedItemId

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);
}
Also used : TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) JaxbHelper(org.platformlayer.xml.JaxbHelper) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Aggregations

ManagedItemId (org.platformlayer.ids.ManagedItemId)20 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)13 ProjectId (org.platformlayer.ids.ProjectId)9 RepositoryException (org.platformlayer.RepositoryException)7 ItemType (org.platformlayer.ids.ItemType)5 ServiceType (org.platformlayer.ids.ServiceType)5 FederationKey (org.platformlayer.ids.FederationKey)4 JobData (org.platformlayer.jobs.model.JobData)4 OpsException (org.platformlayer.ops.OpsException)4 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)3 SQLException (java.sql.SQLException)3 AesCryptoKey (com.fathomdb.crypto.AesCryptoKey)2 CryptoKey (com.fathomdb.crypto.CryptoKey)2 Path (javax.ws.rs.Path)2 SecretProvider (org.platformlayer.auth.crypto.SecretProvider)2 ModelClass (org.platformlayer.xaas.services.ModelClass)2 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)2 JaxbHelper (org.platformlayer.xml.JaxbHelper)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1