Search in sources :

Example 6 with RepositoryException

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

the class OpsContextBuilder method buildOpsContext.

public OpsContext buildOpsContext(ActiveJobExecution activeJob) throws OpsException {
    ServiceType serviceType = activeJob.getServiceType();
    ProjectAuthorization projectAuthz = activeJob.getProjectAuthorization();
    List<ProjectAuthorization> projects = Lists.newArrayList();
    // .getProject();
    ProjectAuthorization runAsProject = projectAuthz;
    projects.add(runAsProject);
    MultitenantConfiguration multitenant = opsSystem.getMultitenantConfiguration();
    if (multitenant != null) {
        ProjectAuthorization masterProject = multitenant.getMasterProject();
        if (runAsProject.getName().equals(masterProject.getName())) {
            // We're in the master project
            multitenant = null;
        } else {
            runAsProject = masterProject;
            projects.add(runAsProject);
        }
    }
    TypedPlatformLayerClient defaultClient = buildClient(runAsProject);
    FederationConfiguration federationMapConfig = FederatedPlatformLayerClient.buildFederationConfiguration(defaultClient);
    FederationMap federationMap = new FederationMap(httpStrategy, mapper, federationMapConfig);
    if (multitenant != null) {
        // .getProject();
        ProjectAuthorization localProject = projectAuthz;
        TypedPlatformLayerClient localClient = buildClient(localProject);
        FederationKey host = FederationKey.LOCAL;
        ProjectId project = localClient.getProject();
        FederationMapping mapKey = new FederationMapping(host, project);
        federationMap.addMapping(mapKey, localClient);
        for (PlatformLayerKey mappedService : multitenant.getMappedItems()) {
            FederationMap.Rule rule = new FederationMap.Rule();
            rule.mappedItems = mappedService;
            rule.targetKey = mapKey;
            federationMap.addRule(rule);
        }
    }
    ProjectId runAsProjectId = new ProjectId(runAsProject.getName());
    PlatformLayerClient platformLayerClient;
    if (federationMap.isEmpty()) {
        platformLayerClient = defaultClient;
    } else {
        federationMap.addDefault(defaultClient);
        platformLayerClient = FederatedPlatformLayerClient.build(runAsProjectId, federationMap);
    }
    ServiceConfiguration serviceConfiguration = new ServiceConfiguration(runAsProjectId, serviceType);
    ServiceAuthorization serviceAuthorization;
    try {
        serviceAuthorization = serviceAuthorizationService.findServiceAuthorization(serviceType, runAsProjectId);
        // }
        if (serviceAuthorization == null) {
            serviceAuthorization = new ServiceAuthorization();
            serviceAuthorization.serviceType = serviceConfiguration.getServiceType().getKey();
        }
    } catch (RepositoryException e) {
        throw new OpsException("Error reading from repository", e);
    }
    // OpsConfig opsConfig = OpsConfig.build(serviceAuthorization);
    // UserInfo userInfo = new SimpleUserInfo(auth, opsConfig);
    OpsContext opsContext = new OpsContext(opsSystem, activeJob, serviceConfiguration, platformLayerClient, projects);
    return opsContext;
}
Also used : TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) OpsException(org.platformlayer.ops.OpsException) ProjectId(org.platformlayer.ids.ProjectId) FederationMap(org.platformlayer.federation.FederationMap) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) RepositoryException(org.platformlayer.RepositoryException) OpsContext(org.platformlayer.ops.OpsContext) MultitenantConfiguration(org.platformlayer.ops.MultitenantConfiguration) FederationKey(org.platformlayer.ids.FederationKey) ServiceAuthorization(org.platformlayer.xaas.model.ServiceAuthorization) DirectPlatformLayerClient(org.platformlayer.ops.DirectPlatformLayerClient) FederatedPlatformLayerClient(org.platformlayer.federation.FederatedPlatformLayerClient) PlatformLayerClient(org.platformlayer.PlatformLayerClient) TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) FederationConfiguration(org.platformlayer.federation.model.FederationConfiguration) ServiceConfiguration(org.platformlayer.ops.ServiceConfiguration) ServiceType(org.platformlayer.ids.ServiceType) ProjectAuthorization(org.platformlayer.model.ProjectAuthorization) FederationMapping(org.platformlayer.federation.FederationMapping)

Example 7 with RepositoryException

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

the class SchedulerImpl method putJob.

@Override
public void putJob(SchedulerRecord record) throws OpsException {
    ensureStarted();
    scheduleRecord(record, false);
    try {
        repository.put(record);
    } catch (RepositoryException e) {
        throw new OpsException("Error persisting record", e);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) RepositoryException(org.platformlayer.RepositoryException)

Example 8 with RepositoryException

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

the class OperationQueueBase method createExecution.

protected JobExecutionData createExecution(JobData jobData) throws OpsException {
    Date startedAt = new Date();
    String executionId;
    try {
        executionId = jobRepository.insertExecution(jobData.key, startedAt);
    } catch (RepositoryException e) {
        throw new OpsException("Error inserting job execution into repository", e);
    }
    JobExecutionData execution = new JobExecutionData();
    execution.job = jobData;
    execution.jobKey = jobData.getJobKey();
    execution.startedAt = startedAt;
    execution.executionId = executionId;
    execution.state = JobState.PRESTART;
    return execution;
}
Also used : OpsException(org.platformlayer.ops.OpsException) JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) RepositoryException(org.platformlayer.RepositoryException) Date(java.util.Date)

Example 9 with RepositoryException

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

the class DirectPlatformLayerClient method findItem.

@Override
public <T> T findItem(PlatformLayerKey key) throws PlatformLayerClientException {
    key = resolveKey(key);
    boolean fetchTags = true;
    ItemBase managedItem;
    try {
        managedItem = itemRepository.getManagedItem(key, fetchTags, getSecretProvider());
    } catch (RepositoryException e) {
        throw new PlatformLayerClientException("Error fetching item", e);
    }
    return (T) managedItem;
}
Also used : PlatformLayerClientException(org.platformlayer.PlatformLayerClientException) ItemBase(org.platformlayer.core.model.ItemBase) RepositoryException(org.platformlayer.RepositoryException)

Example 10 with RepositoryException

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

the class JdbcJobRepository method recordJobEnd.

@Override
@JdbcTransaction
public void recordJobEnd(PlatformLayerKey jobKey, String executionId, Date endedAt, JobState state, String logCookie) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        ProjectId project = jobKey.getProject();
        String jobId = jobKey.getItemIdString();
        int projectId = db.mapToValue(project);
        int updateCount = db.queries.updateExecution(logCookie, endedAt, state, projectId, jobId, executionId);
        if (updateCount != 1) {
            throw new RepositoryException("Unexpected number of rows updated");
        }
        updateCount = db.queries.updateJob(endedAt, state, executionId, projectId, jobId);
        if (updateCount != 1) {
            throw new RepositoryException("Unexpected number of rows updated");
        }
    } catch (SQLException e) {
        throw new RepositoryException("Error updating 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