Search in sources :

Example 1 with ServiceConfiguration

use of org.platformlayer.ops.ServiceConfiguration 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 2 with ServiceConfiguration

use of org.platformlayer.ops.ServiceConfiguration in project platformlayer by platformlayer.

the class ProjectContext method getProjectId.

public ProjectId getProjectId() {
    ServiceConfiguration serviceConfiguration = OpsContext.get().getServiceConfiguration();
    ProjectId project = serviceConfiguration.getProject();
    PlatformLayerKey targetItemKey = opsContext.getJobRecord().getTargetItemKey();
    if (targetItemKey != null) {
        ProjectId project2 = targetItemKey.getProject();
        if (!project.equals(project2)) {
            // Not sure yet which one we should be using if these differ!
            throw new IllegalStateException();
        }
    }
    return project;
}
Also used : ServiceConfiguration(org.platformlayer.ops.ServiceConfiguration) ProjectId(org.platformlayer.ids.ProjectId) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 3 with ServiceConfiguration

use of org.platformlayer.ops.ServiceConfiguration in project platformlayer by platformlayer.

the class SshKeys method findOtherServiceKey.

@Deprecated
public SshKey findOtherServiceKey(ServiceType serviceType) throws OpsException {
    ServiceConfiguration serviceConfiguration = opsContext.getServiceConfiguration();
    KeyPair sshKeyPair = privateData.findSshKey(serviceConfiguration.getProject(), serviceType);
    return new SshKey(null, "root", sshKeyPair);
}
Also used : KeyPair(java.security.KeyPair) ServiceConfiguration(org.platformlayer.ops.ServiceConfiguration)

Aggregations

ServiceConfiguration (org.platformlayer.ops.ServiceConfiguration)3 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 ProjectId (org.platformlayer.ids.ProjectId)2 KeyPair (java.security.KeyPair)1 PlatformLayerClient (org.platformlayer.PlatformLayerClient)1 RepositoryException (org.platformlayer.RepositoryException)1 TypedPlatformLayerClient (org.platformlayer.TypedPlatformLayerClient)1 FederatedPlatformLayerClient (org.platformlayer.federation.FederatedPlatformLayerClient)1 FederationMap (org.platformlayer.federation.FederationMap)1 FederationMapping (org.platformlayer.federation.FederationMapping)1 FederationConfiguration (org.platformlayer.federation.model.FederationConfiguration)1 FederationKey (org.platformlayer.ids.FederationKey)1 ServiceType (org.platformlayer.ids.ServiceType)1 ProjectAuthorization (org.platformlayer.model.ProjectAuthorization)1 DirectPlatformLayerClient (org.platformlayer.ops.DirectPlatformLayerClient)1 MultitenantConfiguration (org.platformlayer.ops.MultitenantConfiguration)1 OpsContext (org.platformlayer.ops.OpsContext)1 OpsException (org.platformlayer.ops.OpsException)1 ServiceAuthorization (org.platformlayer.xaas.model.ServiceAuthorization)1