Search in sources :

Example 6 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 7 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 8 with TypedPlatformLayerClient

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

the class PlatformLayerTestContext method getItem.

public <T extends ItemBase> T getItem(String id, Class<T> itemClass) throws OpsException, IOException {
    TypedPlatformLayerClient client = getTypedClient();
    JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(itemClass, new Class[] {});
    PlatformLayerKey key = PlatformLayerClientBase.toKey(jaxbHelper, new ManagedItemId(id), itemClass, client.listServices(true));
    return client.getItem(key, itemClass);
}
Also used : TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) JaxbHelper(org.platformlayer.xml.JaxbHelper) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Example 9 with TypedPlatformLayerClient

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

the class FederatedPlatformLayerClient method buildClients.

// public static FederatedPlatformLayerClient buildUsingSavedConfiguration(String key) throws IOException {
// File credentialsFile = new File(System.getProperty("user.home") + File.separator + ".credentials" +
// File.separator + key);
// if (!credentialsFile.exists())
// throw new FileNotFoundException("Configuration file not found: " + credentialsFile);
// Properties properties = new Properties();
// try {
// properties.load(new FileInputStream(credentialsFile));
// } catch (IOException e) {
// throw new IOException("Error reading configuration file: " + credentialsFile, e);
// }
// return buildUsingProperties(properties);
// }
// public static FederatedPlatformLayerClient buildUsingConfig(InputStream is, TypedItemMapper mapper)
// throws OpsException {
// FederationConfiguration federationMapConfig = SmartDeserialization.deserialize(FederationConfiguration.class,
// is);
// FederationMap federationMap = new FederationMap(mapper, federationMapConfig);
//
// // int parallelism = Runtime.getRuntime().availableProcessors();
// // // Because we're doing lots of HTTP requests, rather than being CPU bound, we massively increase the
// // parallelism
// // parallelism *= 256;
//
// ForkJoinStrategy forkJoinPool = new FakeForkJoinStrategy();
//
// return new FederatedPlatformLayerClient(federationMap, forkJoinPool);
// }
void buildClients() {
    for (FederationMapping key : federationMap.getAllTargetKeys()) {
        TypedPlatformLayerClient client = federationMap.buildClient(key);
        ChildClient child = new ChildClient(key, client);
        childClients.put(key, child);
    }
    if (childClients.isEmpty()) {
        throw new IllegalStateException();
    }
}
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