Search in sources :

Example 1 with TypedPlatformLayerClient

use of org.platformlayer.TypedPlatformLayerClient 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 TypedPlatformLayerClient

use of org.platformlayer.TypedPlatformLayerClient 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 TypedPlatformLayerClient

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

the class PlatformLayerTestContext method doAction.

public <T extends ItemBase> JobData doAction(T item, Action action) throws OpsException, IOException {
    TypedPlatformLayerClient client = getTypedClient();
    PlatformLayerKey key = item.getKey();
    return client.doAction(key, action);
}
Also used : TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 4 with TypedPlatformLayerClient

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

the class PlatformLayerTestContext method deleteItem.

public <T extends ItemBase> JobData deleteItem(T item) throws IOException, OpsException {
    TypedPlatformLayerClient client = getTypedClient();
    PlatformLayerKey key = item.getKey();
    return client.deleteItem(key);
}
Also used : TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 5 with TypedPlatformLayerClient

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

the class PlatformLayerTestContext method putItem.

public <T extends ItemBase> T putItem(String id, T item) throws OpsException, IOException {
    TypedPlatformLayerClient client = getTypedClient();
    Class<T> itemClass = (Class<T>) item.getClass();
    item.key = PlatformLayerKey.fromId(id);
    T put = client.putItem(item);
    ownedItems.add(put);
    return put;
}
Also used : TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient)

Aggregations

TypedPlatformLayerClient (org.platformlayer.TypedPlatformLayerClient)9 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)5 PlatformLayerClient (org.platformlayer.PlatformLayerClient)3 FederatedPlatformLayerClient (org.platformlayer.federation.FederatedPlatformLayerClient)2 ProjectId (org.platformlayer.ids.ProjectId)2 DirectPlatformLayerClient (org.platformlayer.ops.DirectPlatformLayerClient)2 OpsException (org.platformlayer.ops.OpsException)2 HttpPlatformLayerClient (org.platformlayer.HttpPlatformLayerClient)1 RepositoryException (org.platformlayer.RepositoryException)1 TypedItemMapper (org.platformlayer.TypedItemMapper)1 DirectAuthenticator (org.platformlayer.auth.DirectAuthenticator)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 ManagedItemId (org.platformlayer.ids.ManagedItemId)1 ServiceType (org.platformlayer.ids.ServiceType)1 JobData (org.platformlayer.jobs.model.JobData)1 JobExecutionData (org.platformlayer.jobs.model.JobExecutionData)1 JobExecutionList (org.platformlayer.jobs.model.JobExecutionList)1