Search in sources :

Example 1 with FederationRule

use of org.platformlayer.federation.model.FederationRule in project platformlayer by platformlayer.

the class FederatedPlatformLayerClient method buildFederationConfiguration.

// public static FederationMap buildFederationMap(HttpStrategy httpStrategy, TypedPlatformLayerClient localClient,
// TypedItemMapper mapper) throws OpsException {
// FederationConfiguration federationMapConfig = buildFederationConfiguration(localClient);
//
// FederationMap federationMap = new FederationMap(httpStrategy, mapper, federationMapConfig);
//
// if (localClient != null) {
// federationMap.addDefault(localClient);
// }
//
// return federationMap;
// }
public static FederationConfiguration buildFederationConfiguration(TypedPlatformLayerClient localClient) throws OpsException {
    FederationConfiguration federationMapConfig = new FederationConfiguration();
    String federationNamespace = "http://platformlayer.org/service/federation/v1.0";
    boolean federationEnabled = isServiceEnabled(localClient, federationNamespace);
    if (federationEnabled) {
        for (FederatedService service : localClient.listItems(FederatedService.class)) {
            PlatformLayerConnectionConfiguration config = new PlatformLayerConnectionConfiguration();
            config.key = service.getKey();
            config.secret = service.getSecret();
            config.authenticationEndpoint = service.getServer();
            config.tenant = service.getTenant();
            config.username = service.getUsername();
            config.platformlayerEndpoint = service.getServer();
            federationMapConfig.systems.add(config);
        }
        for (FederatedServiceMap map : localClient.listItems(FederatedServiceMap.class)) {
            FederationRule rule = new FederationRule();
            rule.target = map.getTarget();
            rule.serviceType = map.getServiceType();
            federationMapConfig.rules.add(rule);
        }
    }
    return federationMapConfig;
}
Also used : FederationConfiguration(org.platformlayer.federation.model.FederationConfiguration) PlatformLayerConnectionConfiguration(org.platformlayer.federation.model.PlatformLayerConnectionConfiguration) FederatedServiceMap(org.platformlayer.service.federation.v1.FederatedServiceMap) FederationRule(org.platformlayer.federation.model.FederationRule) FederatedService(org.platformlayer.service.federation.v1.FederatedService)

Example 2 with FederationRule

use of org.platformlayer.federation.model.FederationRule in project platformlayer by platformlayer.

the class FederationMap method buildRules.

private void buildRules(FederationConfiguration config) {
    for (FederationRule federationRule : config.rules) {
        Rule rule = new Rule();
        rule.mappedItems = PlatformLayerKey.fromServiceAndItem(federationRule.serviceType, null);
        for (PlatformLayerConnectionConfiguration system : config.systems) {
            if (Objects.equal(system.key, federationRule.target)) {
                if (rule.targetKey != null) {
                    throw new IllegalStateException();
                }
                FederationKey host = FederationKey.build(system.authenticationEndpoint);
                ProjectId project = new ProjectId(system.tenant);
                rule.targetKey = new FederationMapping(host, project);
            }
        }
        if (rule.targetKey == null) {
            throw new IllegalStateException();
        }
        addRule(rule);
    }
}
Also used : FederationRule(org.platformlayer.federation.model.FederationRule) PlatformLayerConnectionConfiguration(org.platformlayer.federation.model.PlatformLayerConnectionConfiguration) ProjectId(org.platformlayer.ids.ProjectId) FederationRule(org.platformlayer.federation.model.FederationRule) FederationKey(org.platformlayer.ids.FederationKey)

Aggregations

FederationRule (org.platformlayer.federation.model.FederationRule)2 PlatformLayerConnectionConfiguration (org.platformlayer.federation.model.PlatformLayerConnectionConfiguration)2 FederationConfiguration (org.platformlayer.federation.model.FederationConfiguration)1 FederationKey (org.platformlayer.ids.FederationKey)1 ProjectId (org.platformlayer.ids.ProjectId)1 FederatedService (org.platformlayer.service.federation.v1.FederatedService)1 FederatedServiceMap (org.platformlayer.service.federation.v1.FederatedServiceMap)1