Search in sources :

Example 1 with ProjectId

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);
}
Also used : DirectPlatformLayerClient(org.platformlayer.ops.DirectPlatformLayerClient) FederatedPlatformLayerClient(org.platformlayer.federation.FederatedPlatformLayerClient) PlatformLayerClient(org.platformlayer.PlatformLayerClient) TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) PlatformLayerHelpers(org.platformlayer.ops.machines.PlatformLayerHelpers) DirectPlatformLayerClient(org.platformlayer.ops.DirectPlatformLayerClient) ProjectId(org.platformlayer.ids.ProjectId) DirectAuthenticator(org.platformlayer.auth.DirectAuthenticator) PlatformLayerTypedItemMapper(org.platformlayer.ops.machines.PlatformLayerTypedItemMapper) TypedItemMapper(org.platformlayer.TypedItemMapper) DirectAuthentication(org.platformlayer.ops.DirectAuthentication)

Example 2 with ProjectId

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;
}
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 3 with ProjectId

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

Example 4 with ProjectId

use of org.platformlayer.ids.ProjectId in project platformlayer by platformlayer.

the class FederationMap method buildTargetMap.

private void buildTargetMap(FederationConfiguration config) {
    for (PlatformLayerConnectionConfiguration child : config.systems) {
        FederationKey host = FederationKey.build(child.authenticationEndpoint);
        ProjectId project = new ProjectId(child.tenant);
        FederationMapping key = new FederationMapping(host, project);
        MappedTarget target = new MappedTarget();
        target.configuration = child;
        addMapping(key, target);
    }
}
Also used : PlatformLayerConnectionConfiguration(org.platformlayer.federation.model.PlatformLayerConnectionConfiguration) ProjectId(org.platformlayer.ids.ProjectId) FederationKey(org.platformlayer.ids.FederationKey)

Example 5 with ProjectId

use of org.platformlayer.ids.ProjectId in project platformlayer by platformlayer.

the class FederationMap method toKey.

private FederationMapping toKey(PlatformLayerKey original, Rule rule) {
    FederationKey targetHost = original.getHost();
    ProjectId targetProject = original.getProject();
    if (rule.targetKey != null) {
        MappedTarget target = targetMap.get(rule.targetKey);
        if (target == null) {
            throw new IllegalStateException("Cannot find target: " + rule.targetKey);
        }
        targetHost = rule.targetKey.host;
        targetProject = rule.targetKey.project;
    }
    return new FederationMapping(targetHost, targetProject);
}
Also used : ProjectId(org.platformlayer.ids.ProjectId) FederationKey(org.platformlayer.ids.FederationKey)

Aggregations

ProjectId (org.platformlayer.ids.ProjectId)33 RepositoryException (org.platformlayer.RepositoryException)14 FederationKey (org.platformlayer.ids.FederationKey)11 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)10 ManagedItemId (org.platformlayer.ids.ManagedItemId)9 OpsException (org.platformlayer.ops.OpsException)8 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)7 SQLException (java.sql.SQLException)7 ServiceType (org.platformlayer.ids.ServiceType)7 ItemType (org.platformlayer.ids.ItemType)6 ProjectAuthorization (org.platformlayer.model.ProjectAuthorization)4 PlatformLayerClient (org.platformlayer.PlatformLayerClient)3 ItemBase (org.platformlayer.core.model.ItemBase)3 JobData (org.platformlayer.jobs.model.JobData)3 TypedPlatformLayerClient (org.platformlayer.TypedPlatformLayerClient)2 Authenticator (org.platformlayer.auth.Authenticator)2 DirectAuthenticator (org.platformlayer.auth.DirectAuthenticator)2 FederatedPlatformLayerClient (org.platformlayer.federation.FederatedPlatformLayerClient)2 PlatformLayerConnectionConfiguration (org.platformlayer.federation.model.PlatformLayerConnectionConfiguration)2 DirectPlatformLayerClient (org.platformlayer.ops.DirectPlatformLayerClient)2