use of org.platformlayer.ids.ProjectId 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();
}
}
use of org.platformlayer.ids.ProjectId in project platformlayer by platformlayer.
the class JdbcJobRepository method findJob.
@Override
@JdbcTransaction
public JobData findJob(PlatformLayerKey jobKey) throws RepositoryException {
DbHelper db = new DbHelper();
try {
ProjectId projectId = jobKey.getProject();
String jobId = jobKey.getItemIdString();
JobEntity execution = db.queries.findJob(db.mapToValue(projectId), jobId);
if (execution == null) {
return null;
}
return mapFromEntity(execution, jobKey);
} catch (SQLException e) {
throw new RepositoryException("Error listing job executions", e);
} finally {
db.close();
}
}
use of org.platformlayer.ids.ProjectId in project platformlayer by platformlayer.
the class OpsContextBuilder method buildClient.
private TypedPlatformLayerClient buildClient(ProjectAuthorization project) throws OpsException {
ProjectId projectId = new ProjectId(project.getName());
DirectAuthenticator directAuthenticator = buildDirectAuthenticator(project);
// TODO: Introduce a direct client for "loopback" (normal) calls?
String platformLayerUrl = OpsSystem.getPlatformLayerUrlBase();
List<String> trustKeys = opsSystem.getServerTrustKeys();
PlatformLayerClient client;
// client = HttpPlatformLayerClient.build(httpStrategy, platformLayerUrl,
// directAuthenticator, projectId, trustKeys);
DirectAuthentication auth = new DirectAuthentication(project);
TypedItemMapper mapper = null;
client = new DirectPlatformLayerClient(mapper, opsSystem, projectId, auth);
return new PlatformLayerHelpers(client, serviceProviderHelpers);
}
use of org.platformlayer.ids.ProjectId 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;
}
use of org.platformlayer.ids.ProjectId in project platformlayer by platformlayer.
the class PlatformLayerKey method build.
public static PlatformLayerKey build(String host, String project, String serviceType, String itemType, String itemId) {
FederationKey federationKey = host != null ? FederationKey.build(host) : null;
ProjectId projectKey = project != null ? new ProjectId(project) : null;
ServiceType serviceKey = serviceType != null ? new ServiceType(serviceType) : null;
ItemType itemKey = itemType != null ? new ItemType(itemType) : null;
ManagedItemId idKey = itemId != null ? new ManagedItemId(itemId) : null;
return new PlatformLayerKey(federationKey, projectKey, serviceKey, itemKey, idKey);
}
Aggregations